-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint_fft.cpp
108 lines (94 loc) · 1.71 KB
/
int_fft.cpp
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
#include<iostream>
#include<math.h>
using namespace std;
int ISPRIME(int p) ;
int FINDPRIME(int N, int start) ;
int FINDBASIS(int p, int t);
int main()
{
int N=1, p, s ,M ,t=1 ;
cin >> s;
for ( int i = 0 ; i< s ;i++) N = N*2 ;
M = 2 * (int(log10(N))+1) ; // length of the number * 2
while ( t < M) { t *= 2; } // t is the length of power of 2 such that t > M
int W = 0 ;
while ( W == 0 )
{
p = FINDPRIME(N, 1 ) ;
W = FINDBASIS(p, t) ; // basis element
}
// p = FINDPRIME(N, 1 ) ;
// int b = FINDBASIS(p, t) ;
//
// for ( int i = 0 ; i< t; i ++)
// {
// cout << b << endl ;
// b*= b ;
// b = b% p ;
// }
// cout << t << endl ;
cout << p << endl ;
cout << W << endl ;
for ( int i = 0 ; i < t ; i++)
{
int r = 1 ;
for ( int j = 0 ; j <t ; j++)
{
for ( int l = 0 ; l < i*j ; l++) r = r*W % p;
cout << r << " " ;
}
cout << endl ;
}
int o = 1 ;
for ( int i = 0 ; i< 10 ; i++)
{
cout << o << endl ;
o = o * W % p ;
}
}
int ISPRIME(int p)
{
int i = 2 ;
while ( (p%i)!= 0 && i < sqrt(p) )
{ i ++ ; }
if ( (p%i) != 0 ) return 1 ; // if p is prime, cout 1. else cout 0.
else return 0 ;
}
int FINDPRIME(int N , int start )
{
int p = start ;
int r = 0 ;
int M = int(log10(N) ) +1 ; // number of digits
while(r == 0 )
{
if ( p > 81*(M) && ISPRIME(p) == 1 ) r = 1 ;
else p += 8 ;
}
return p ;
}
int FINDBASIS(int p, int t)
{
int i = 1 ;
while( i < p )
{
int m = 1 ;
for ( int k = 0 ; k< t ; k ++)
{
m *= i ;
m = m % p ;
}
if ( m == 1 )
{
m = 1 ;
for ( int j = 0 ; j < t-1 ; j ++)
{
m *= i ;
m = m % p ;
if ( m == 1 ) break ;
}
if ( m!= 1 ) return i ;
}
i++ ;
}
return 0 ;
}