Codeforces 113C
C. Double Happinesstime limit per test5 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputOn the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as:
t = a2 + b2, where a, b are arbitrary positive integers.Now, the boys decided to find out how many days of the interval [l, r] (l ≤ r) are suitable for pair programming. They decided that the day i (l ≤ i ≤ r) is suitable for pair programming if and only if the number i is lucky for Peter and lucky for Bob at the same time. Help the boys to find the number of such days.
InputThe first line of the input contains integer numbers l, r (1 ≤ l, r ≤ 3·108).
OutputIn the only line print the number of days on the segment [l, r], which are lucky for Peter and Bob at the same time.
Sample test(s)input3 5output1input6 66output7
1 /************************************************************************* 2 > File Name: 113C.cpp 3 > Author: Stomach_ache 4 > Mail: sudaweitong@gmail.com 5 > Created Time: 2014年07月20日 星期日 13时34分53秒 6 > Propose: 7 ************************************************************************/ 8 9 #include <cmath> 10 #include <string> 11 #include <bitset> 12 #include <cstdio> 13 #include <fstream> 14 #include <cstring> 15 #include <iostream> 16 #include <algorithm> 17 using namespace std; 18 19 const int maxn = 1e8+1e8+1e8; 20 bitset<maxn> p; 21 22 int 23 main(void) { 24 int L, R; 25 scanf("%d %d\n", &L, &R); 26 p.set(); 27 for (int i = 3; i*i <= R; i+=2) if (p[i]) for (int j = i*i; j <= R; j+=2*i) p[j] = false; 28 int ans = 0; 29 for (int i = 5; i <= R; i+=4) if (p[i] && i >= L) ans++; 30 ans += (L <= 2 && R >= 2) ? 1 : 0; 31 printf("%d\n", ans); 32 33 return 0; 34 }
posted on 2014-07-20 14:23 Stomach_ache 阅读(263) 评论(0) 编辑 收藏 举报