Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Riemann's prime number formula
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#include "bits/stdc++.h" using namespace std; int factorial(int x) { if (x == 1) return x; return x * factorial(x - 1); } double Ei(double x) { double ec = 0.5772156649; double a = log(x); double b = 0; for (int k = 1; k < 10; ++k) { b += pow(x, k) / (k * factorial(k)); } return ec + a + b; } double Li(double x) { return Ei(log(x)); } int main() { int mebius[] = { 0, 1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1 }; double p[] = { 14.134725142, 21.022039639, 25.010857580, 30.424876126, 32.935061588, 37.586178159, 40.918719012, 43.327073281, 48.005150881, 49.773832478, 52.970321478, 56.446247697, 59.347044003, 60.831778525, 65.112544048, 67.079810529, 69.546401711, 72.067157674, 75.704690699, 77.144840069, 79.337375020, 82.910380854, 84.735492981, 87.425274613, 88.809111208, 92.491899271, 94.651344041, 95.870634228, 98.831194218, 101.317851006, 103.725538040, 105.446623052, 107.168611184, 111.029535543, 111.874659177, 114.320220915, 116.226680321, 118.790782866, 121.370125002, 122.946829294, 124.256818554, 127.516683880, 129.578704200, 131.087688531, 133.497737203, 134.756509753, 138.116042055, 139.736208952, 141.123707404, 143.111845808, 146.000982487, 147.422765343, 150.053520421, 150.925257612, 153.024693811, 156.112909294, 157.597591818, 158.849988171, 161.188964138, 163.030709687, 165.537069188, 167.184439978, 169.094515416, 169.911976479, 173.411536520, 174.754191523, 176.441434298, 178.377407776, 179.916484020, 182.207078484, 184.874467848, 185.598783678, 187.228922584, 189.416158656, 192.026656361, 193.079726604, 195.265396680, 196.876481841, 198.015309676, 201.264751944, 202.493594514, 204.189671803, 205.394697202, 207.906258888, 209.576509717, 211.690862595, 213.347919360, 214.547044783, 216.169538508, 219.067596349, 220.714918839, 221.430705555, 224.007000255, 224.983324670, 227.421444280, 229.337413306, 231.250188700, 231.987235253, 233.693404179, 236.524229666, 237.769820481, 239.555477573, 241.049157796, 242.823271934, 244.070898497, 247.136990075, 248.101990060, 249.573689645, 251.014947795, 253.069986748, 255.306256455, 256.380713694, 258.610439492, 259.874406990, 260.805084505, 263.573893905, 265.557851839, 266.614973782, 267.921915083, 269.970449024, 271.494055642, 273.459609188, 275.587492649, 276.452049503, 278.250743530, 279.229250928, 282.465114765, 283.211185733, 284.835963981, 286.667445363, 287.911920501 }; int N = 1000; int m = log(N); double r = 0; for (int i = 1; i < m + 1; ++i) { r += mebius[i] / i * Li(pow(N,1./i)); } double t = 0; for (int k = 0; k < 100; ++k) { double b = 0; for (int i = 1; i < m + 1; ++i) { double z = sqrt(0.25 + pow(p[k], 2)); b += mebius[i] / m * 2 * sqrt(i) / z * cos(p[k] * log(i) - atan(2*p[k])); } t -= b; } cout << (r + t) << endl; return EXIT_SUCCESS; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.32 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 1,48 sec
edit mode
|
history
|
discussion
163.052