#include #include #include #include #include NTL_CLIENT using namespace std; RR sinh(RR x) { return (exp(x)-exp(-x))/to_RR(2); } RR cosh(RR x) { return (exp(x)+exp(-x))/to_RR(2); } int Int(RR x) { return to_long(RoundToZZ(x)); } int main(int argc, char *argv[]) { double n =1000000; int bin_digits= (int) (50+3.1416*sqrt(2*n/3)/log(2)); RR::SetPrecision(bin_digits); RR _PI = ComputePi_RR(); RR a, b, c, x, d,h,k,r; for (k = 1; k*k <= n; ++k) { a = sqrt(k)*pow(to_RR(n)-to_RR(1)/to_RR(24),to_RR(-3/2.)); b= sqrt(to_RR(2)/to_RR(3)*_PI*_PI/k/k*(to_RR(n)-to_RR(1)/to_RR(24)) ); b = b * cosh(b) - sinh(b); for (c = 0, h = 1; h <= k; ++h) if (GCD(Int(h), Int(k))==1) { for (d = 0, r = 1; r <= k-1; ++r) d += r/k*(h*r/k - floor(h*r/k) - 1/2.); c += cos(_PI*(d - to_RR(2.*h*n/k))); } x += a * b * c; cout << k << endl; } cout << round(x/_PI/sqrt(to_RR(8))) << endl; ofstream out("result1e6.txt"); out << round(x/_PI/sqrt(to_RR(8))) << endl; system("PAUSE"); return EXIT_SUCCESS; }