-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path358.c
138 lines (127 loc) · 2.93 KB
/
358.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LIMIT 10000000
unsigned long long * sieveOfEratosthenes(){
int *marks;
unsigned long long *primes;
marks = calloc(LIMIT+1,sizeof(int));
primes = calloc(LIMIT+1,sizeof(unsigned long long));
for (int i=2;i<LIMIT+1;i++){
marks[i]=1;
}
for (int i=2;i<sqrt(LIMIT)+1;i++){
if (marks[i]){
for (int j=i*i;j<LIMIT+1;j+=i){
marks[j] = 0;
}
}
}
unsigned long long ctr = 0;
for (unsigned long long i=2;i<LIMIT+1;i++){
if (marks[i]){
primes[ctr] = i;
ctr++;
}
}
free(marks);
return primes;
}
unsigned long long * distinctPrimeFactors(unsigned long long n, unsigned long long *primes){
unsigned long long ctr = 0, index = 0, *exponents, original = n;
int flag = 0;
exponents = calloc(sqrt(LIMIT)+1,sizeof(unsigned long long));
while(n!=1){
while(n%primes[ctr]==0){
n = n/primes[ctr];
flag = 1;
}
if (flag){
// printf("INIT %d\n",primes[ctr]);
exponents[index] = original/primes[ctr];
flag = 0;
index++;
}
ctr++;
}
return exponents;
}
unsigned long long constructCyclic(unsigned long long p){
unsigned long long b = 10;
unsigned long long t = 0;
unsigned long long r = 1;
unsigned long long x,d;
int array[5] = {7,4,6,7,1};
int ctr = 0;
unsigned long long total = 0;
while (1){
t++;
x = r * b;
d = (int)(x/p);
r = x%p;
total+=d;
if (r==1){
break;
}
ctr++;
}
return total;
// if (t==(p-1)){
// return 1;
// }
// return 0;
}
int modular_pow(unsigned long long base,unsigned long long exponent,unsigned long long modulus){
if (modulus==1){
return 0;
}
unsigned long long result = 1;
base = base%modulus;
while (exponent>0){
if ((exponent%2)==1){
result = (result*base) % modulus;
}
exponent = exponent >> 1;
base = (base*base) % modulus;
}
if (result==1){
return 0;
}
else{
return 1;
}
}
int isPrimitiveMod10(unsigned long long *exponents, unsigned long long n){
int i = 0;
while(exponents[i]){
if(modular_pow(10,exponents[i],n)==0){
return 0;
}
i++;
}
return 1;
}
int main(){
// unsigned long long *primes = sieveOfEratosthenes();
// unsigned long long a = 725509891;
// unsigned long long *exponentsa = distinctPrimeFactors(a-1,primes);
// printf("%d\n",isPrimitiveMod10(exponentsa,a));
// unsigned long long b = 726509891;
// unsigned long long *exponentsb = distinctPrimeFactors(b-1,primes);
// printf("%d\n",isPrimitiveMod10(exponentsb,b));
// unsigned long long c = 729809891;
// unsigned long long *exponentsc = distinctPrimeFactors(c-1,primes);
// printf("%d\n",isPrimitiveMod10(exponentsc,c));
printf("%llu\n",constructCyclic(729809891));
// printf("%d\n",constructCyclic(724399657));
// unsigned long long ctr = 37450000,n;
// printf("GENERATING SIEVE\n");
// while(primes[ctr]){
// n = primes[ctr];
// unsigned long long *exponents = distinctPrimeFactors(n-1,primes);
// if(isPrimitiveMod10(exponents,n)){
// printf("%llu\n",n);
// }
// ctr++;
// }
}