Problem Link: 10533 - Digit Primes
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000000
- using namespace std;
- bool prime[M];
- int main(){
- for(int i = 2; i <= sqrt(M); i++)
- if(prime[i] == 0)for(int j = i+i; j <= M; j += i)prime[j] = 1;
- int t1, t2, t;
- cin >> t;
- while(t--){
- cin >> t1, t2;
- int low, high;
- low = min(t1, t2);
- high = max(t1, t2);
- int cnt = 0;
- for(int i = low; i <= high; i++){
- if(prime[i] == 0){
- int sum = 0, j = i, temp;
- while(j > 0){
- temp = i%10;
- sum += temp;
- j /= 10;
- }
- if(sum > 0 && prime[sum] == 0)cnt++;
- }
- }
- cout << cnt << endl;
- }
- return 0;
- }
No comments:
Post a Comment