https://codefights.com/challenge/doXskkj8PMAJ27Epk/main
try to find prime numbers by using sieve of Eratosthenes.
and count luckyprimeprime.
I think this is not difficult though.
int c, t, s, i; int luckyandprimeprime(int l, int r) { int[] p = new int[100001]; s = p.length; for ( i = 2; i < s; i++, t=0) while ((t += i) < s) p[t]++; for (i = 0; i < l; i++) if (p[i] == 1) c++; for (i = l; i <= r; i++) { if (p[i] == 1) c++; if (p[c] == 1) t++; } return t; }
Recently Lucky learnt how to check if the given number is prime or not. Bunny, Lucky's friend, decided to give her a task to test her skills.
Let's call number
P
Prime Prime if the number of prime numbers in the range [1, P]
is prime. Bunny asked Lucky to calculate the number of Prime Prime numbers in the range [l, r]
. Can you you help her?
Example
For
l = 1
and r = 10
, the output should beluckyandprimeprime(l, r) = 4
.
There're
4
prime numbers in the given range: 2
, 3
, 5
and 7
. Thus, Prime Prime numbers are 3
, 4
, 5
and 6
, 4
numbers altogether.
Input/Output
- [time limit] 3000ms (java)
- [input] integer lConstraints:
1 ≤ l ≤ r
. - [input] integer rConstraints:
l ≤ r ≤ 105
. - [output] integerThe number of Prime Prime numbers in the range
[l, r]
.
Recently Lucky learnt how to check if the given number is prime or not. Bunny, Lucky's friend, decided to give her a task to test her skills.
Let's call number
P
Prime Prime if the number of prime numbers in the range [1, P]
is prime. Bunny asked Lucky to calculate the number of Prime Prime numbers in the range [l, r]
. Can you you help her?
Example
For
l = 1
and r = 10
, the output should beluckyandprimeprime(l, r) = 4
.
There're
4
prime numbers in the given range: 2
, 3
, 5
and 7
. Thus, Prime Prime numbers are 3
, 4
, 5
and 6
, 4
numbers altogether.
Input/Output
- [time limit] 3000ms (java)
- [input] integer lConstraints:
1 ≤ l ≤ r
. - [input] integer rConstraints:
l ≤ r ≤ 105
. - [output] integerThe number of Prime Prime numbers in the range
[l, r]
.
No comments:
Post a Comment