Algorithm
Problem Name: beecrowd | 2159
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2159
Approximate Number of Primes
By M.C. Pinto, UNILA Brazil
Timelimit: 1
Schoenfeld and Rosser published a paper in 1962 describing a minimum and a maximum value to the quantity of prime numbers up to n, for n ≥ 17. This quantity is represented by the function (n) and the inequality is shown below.
Your task is, given a natural number n, to compute the interval's minimum and maximum values to the approximate number of primes up to n.
Input
The input is a natural number n (17 ≤ n ≤ 109).
Output
The output is given as two values P and M with 1 decimal place each, such that P < (n) < M according to the given inequality above. These two values have one blank space between them.
Input Samples | Output Samples |
17 |
6.0 7.5 |
50 |
12.8 16.0 |
100 |
21.7 27.3 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main()
{
double n, ans1, ans2;
scanf("%lf", &n);
ans1 = n/log(n);
ans2 = (1.25506)*(n/log(n));
printf("%.1lf %.1lf\n", ans1, ans2);
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double a,b;
while(scanf("%d",&n)!=EOF){
a=n/log(n);
b=1.25506*n/log(n);
printf("%.1lf %.1lf\n",a,b);
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
const N = parseInt(prompt());
var P = (N / Math.log(N)).toFixed(1);
var M = ((1.25506 * N) / Math.log(N)).toFixed(1);
console.log(P + " " + M);
Copy The Code &
Try With Live Editor
Input
Output