Untitled
unknown
plain_text
7 months ago
648 B
1
Indexable
Never
//Bai 7 #include <iostream> using namespace std; typedef long long ll; int p[1000001]; void sieve(){ for(int i = 0; i < 1000001; i++) p[i] = 1; p[0] = p[1] = 0; for(int i = 2; i <= 1000; i++){ if(p[i]){ for(int j = i*i; j <= 1000000; j+=i) p[j] = 0; } } } int cao(int n){ int s = 0; while(n){ s += n%10; n/=10; } return s; } int main(){ freopen("DOCAO.inp","r",stdin); freopen("DOCAO.out","w",stdout); sieve(); int n, h, cnt = 0; cin >> n >> h; for(int i = 2; i <= n; i++){ if(p[i] && cao(i) == h){ ++cnt; cout << i << endl; } } cout << cnt << endl; return 0; }
Leave a Comment