#include #include #define N 2500000 typedef unsigned int uint; uint power(uint x,uint n,uint p); double klsum(uint p,uint g); /* 0 if prime, smallest factor otherwise */ static unsigned short factor[N>>1]; void sieve(void) { int i,j; for (i=((int)sqrt((double)N)-1) | 1;i>=3;i-=2) for (j=(i*3)>>1;j>1;j+=i) factor[j] = (unsigned short)i; } /* Find a generator for U(Z/pZ) */ uint generator(uint p) { int i,k; uint x,y,g,n,t; struct { uint p,e; } q[32]; n = (p-1)>>1, q[0].e = q[0].p = 2, k = 1; while (!(n & 1)) q[0].e <<= 1, n >>= 1; while (n > 1) { t = (uint)factor[n>>1]; if (!t) t = n; if (t == q[k-1].p) q[k-1].e *= q[k-1].p; else { q[k].e = q[k].p = t; k++; } n /= t; } g = 1, n = p-1, x = 1; while (k > 0) { /* find next prime */ if (++x > 3) for (++x;factor[x>>1];x+=2); if ( (y = power(x,(p-1)/n,p)) == 1) continue; for (i=k-1;i>=0;i--) if (power(y,n/q[i].p,p) != 1) { n /= q[i].e; g = (uint)((unsigned long long)g * power(y,n,p) % p); y = power(y,q[i].e,p); q[i] = q[--k]; } } return g; } int main(void) { uint n; double a; sieve(); a = sqrt(0.5); fwrite(&a,sizeof(a),1,stdout); for (n=3;n>1]) { a = klsum(n,generator(n)); fwrite(&a,sizeof(a),1,stdout); } return 0; }