-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
59 lines (48 loc) · 1.15 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* This function should return 1 if x is prime and 0 otherwise */
int isPrime(int x){
if(x <= 1) return 0;
for(int i = 2; i <= sqrt(x); i++){
if(x % i == 0) return 0;
}
return 1;
}
/* This function should return 1 if gcd(x,2)=1 and 0 otherwise */
int isGcd1(int x){
int a = x;
int b = 2;
int r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
if(a == 1) {
return 1;
}else{return 0;}
}
/* This function should return 1 if 9^x-2 mod 5 = 2 and 0 otherwise */
int is2mod5(int x){
if (x % 2 == 0){return 0;}
else {return 1;}
}
int main(void){
int x;
int p, q, r;
printf("What number do you want to test?\n");
scanf("%d", &x);
printf("x is %d\n", x);
p = isPrime(x);
q = isGcd1(x);
r = is2mod5(x);
if ((p && !r) || (!p && q &&!r) || (!p && !q && r)){
printf("You have found a valid x\n");
printf("p is %d, q is %d, and r is %d\n", p,q,r);
} else {
printf("p is %d, q is %d, and r is %d\n", p,q,r);
printf("Try again!\n");
}
return EXIT_SUCCESS;
}