#include <stdio.h>

int main()		//Và cuối cùng đến hàm main của chướng trình 
{
    unsigned long long n,t,y;	//Khai báo n, t, y
    printf("nhap so le n ");
    scanf("%ld",&n);
    printf("nhap t ");
    scanf("%ld",&t);		//Sau đó dùng hàm scanf để nhập n và t từ bàn phím 
    long r = timr(n - 1);	/*Sự dụng hàm tìm r để tìm r với tham số chuyền vào là n = 1
				  và gán giá trị đó cho r*/ 
    int s = tims((n - 1), r);	/*Hàm tìm s cũng như vậy với 2 tham số chuyền vào là n - 1 và r
				  và cũng gán nó cho s*/

    y= nhanbinhphuongcolap(t, r, n);	/*Sau đó sự dụng hàm nhân bình phương có lặp với 3 tham số 
					  truyền vào là t, r và n và gán nó cho y*/
    if((y != 1) && (y != (n - 1))){	//Sự dụng khối lệnh if nếu y khác 1 và y khác (n - 1)
        int j = 1;			//thì gán j = 1
        while((j <= (s - 1)) && (y != (n - 1))){	/*Sử dụng khối lệnh while trong if
						với điều kiện lặp là j <= (s - 1)) và (y != (n - 1) */
        y = (y * y) % n;	//và gán y = (y * y) % n
            if(y == 1){		//Nếu y = 1 
                 printf("la hop so");	//return n là hợp số
                  return 0;
               }
            j++;	//không thì j++
        }
        if(y != (n - 1)){	//và nếu y khác (n - 1)
            printf("la hop so");//thì cũng return n là hợp số
            return 0;
        }
    }

    printf("la so nguyen so");	//Kết thúc vòng lặp if return n là số nguyên tố
    return 0;
}

int timr(long n){		//Tạo hàm tìm s với 1 tham số chuyền vào n
    long s = 1;		//khai báo s = 1
    for(int i = 0; s <= n; i++){	//Gọi vòng lặp for đến khi nào s <= 0
        long r = n / s;			//cho r = n / s
        long c = n % s;			//và c = n % s
        if((c == 0) && (r % 2) != 0 && (r > 0)){	//Nếu c = 0 và (r%2) khác 0 và r > 0
            return r;			//Thì return r
        }
        s = s * 2;		//không thì s = s * 2
    }
    return 0;
}

int tims(long n,long r){	//Tạo hàm tìm s với 2 tham số chuyền vào n và r
    int s = n / r;		//Khai báo s = n / r
    long k = 1;			//và k = 1
    for(int i = 0; i <= n; i++){	//Gọi vòng lặp for chạy từ i = 0 cho đến i <= n
        if(s == k){			//Nếu s = k
            return i;			//Thì return i
        }
        k = k * 2;			//còn không thì k = k * 2
    }
    return 0;
}

int nhanbinhphuongcolap(unsigned long long a, unsigned long long r, unsigned long long n) { 
//Tạo hàm nhân bình phương có lặp với 3 tham số truyền vào a, r, n
        int b = 1;		//Khai báo b = 1, i = 0
        int i = 0;
	int y;		
        int c[100];		//và một mảng c gồm 100 phần tử 
        unsigned long long m = r ;	//Khai báo m và gán bằng r
        while (r  > 0) {	//Gọi vòng lặp while với điều kiện lặp là r > 0
            c[i] = r % 2;	//đầu tiên cho c[i] = r % 2
            r = r / 2;		//Sau đó cho gán r = r / 2
            i++;		//Và i++
        }
        if (m == 0) {		//kết thúc vòng lặp nếu m = 0
            y = b;		//Thì y = b
        } else {	
            int A = a;		//không thì khai báo A lớn và gán bằng a nhỏ
            for (int j = 0; j < i; j++) {
                if (j == 0) {		//Nếu j = 0
                    if (c[j] == 1) {	//và nếu c[j] = 1
                        b = A;		/Thì b = A lớn
                    }
                } else {
                    A = A * A % n;	//Không thì A = A*A % n
                    if (c[j] == 1) {	//Nếu c[j] = 1 
                        b = A * b % n;	//Thì b = A * b % n
                    }
                }
            }
        }
        y = b;		//Kết thúc khối lệnh đó gán y = b
        return y;	//Và return y
    }
 
by

C Language online compiler

Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!

Read inputs from stdin

OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.

#include <stdio.h>
int main()
{
    char name[50];
    printf("Enter name:");
    scanf("%s", name);
    printf("Hello %s \n" , name );
    return 0;
    
}

About C

C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.

Key features:

  • Structured Programming
  • Popular system programming language
  • UNIX, MySQL and Oracle are completely written in C.
  • Supports variety of platforms
  • Efficient and also handle low-level activities.
  • As fast as assembly language and hence used as system development language.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition if-else is used.

if(conditional-expression) {
   // code
} else {
   // code
}

You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to if-else-if ladder.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {  
 // code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition); 

Arrays

Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.

Syntax

One dimentional Array:

data-type array-name[size];

Two dimensional array:

data-type array-name[size][size];

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Two types of functions are present in C

  1. Library Functions:

Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,

  1. User defined functions:

User defined functions are the ones which are written by the programmer based on the requirement.

How to declare a Function

return_type function_name(parameters);

How to call a Function

function_name (parameters)

How to define a Function

return_type function_name(parameters) {  
  //code
}