标签:
原题:
Description
Input
Output
Sample Input
Sample Output
#include<iostream> #include<cmath> #include<cstdio> using namespace std; const int N = 1000000 + 10; int ans[N] = { 0 }; int vis[N]; bool check(int x) { int total=0; while (1) { total += (x % 10); //cout << total << endl; x = x / 10; if (x == 0) break; } if (vis[total] == 0) return 1; else return 0; } int main() { int t, kase = 1; cin >> t; vis[1] = 1; for (int i = 2; i <= N; i++) { if (vis[i] == 0) for (int j = 2; j*i <= N; j++) { vis[j*i] = 1; } } for (int i = 1; i <= N; i++) { if (vis[i] == 0&&check(i)) ans[i] = ans[i - 1] + 1; else ans[i] = ans[i - 1]; } while (t--) { int cnt = 0; int left,right; cin >> left >> right; printf("Case #%d: %d\n", kase++, ans[right]-ans[left-1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/shawn-ji/p/4748886.html