标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15296 Accepted Submission(s):
3421
很耗时间,
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> using namespace std; int isprime(int x) { int i; for(i=2;i<=sqrt(x);i++) /*sqrt(x)要比x/2将近两倍*/ { if(x%i==0) return 0; } return 1; } int ishui(int x) { char a[20]; int i=0,j; int flag=0; while(x>0) { a[i++]=x%10+‘0‘; x=x/10; } a[i]=‘\0‘; int len=strlen(a); for(i=0;i<len/2;i++) { if(a[i]!=a[len-i-1]) { return 0; } } return 1; } int main() { int x,y; while(cin>>x>>y) { int i; for(i=x;i<=y&&i<=9989899;i++) { if(ishui(i)&&isprime(i)) { cout<<i<<endl; } } cout<<endl; } }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4690900.html