#include<bits/stdc++.h> using namespace std; bool mark[1000000]; void sieve() { memset(mark,true,1000000); mark[1]=false; for (int i=4; i<1000000;i+=2) mark[i]=false; for (int i=3;i<1000;i+=2) if (mark[i]) for (int j=i*i;j<1000000;j+=i*2) mark[j]=false; return; } int main() { int n; sieve(); while (scanf("%d",&n)==1) { int rev=0; int temp=n; while (temp) { rev=rev*10+temp%10; temp/=10; } if (mark[n]) { if (mark[rev] && n!=rev) printf("%d is emirp.\n",n); else printf("%d is prime.\n",n); } else printf("%d is not prime.\n",n); } return 0; }
Wednesday, April 27, 2016
UVA 10235 - Simply Emirp : Solution
Unknown
Studying at Shahjalal University of Science and Technology, Sylhet.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment