題意:
(from luckycat)
解 法: 建質數表。
TAG: Prime,
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10235 - Simply Emirp | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/05/25 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
#define N 10000005 | |
typedef long long ll; | |
// declarations | |
int n; | |
bool isprime[N]; | |
// functions | |
int revDig( int v ) | |
{ | |
int ret = 0; | |
while( v ) { | |
ret = (ret*10+v%10); | |
v /= 10; | |
} | |
return ret; | |
} | |
// main function | |
int main( void ) | |
{ | |
// init | |
clr( isprime, true ); | |
isprime[0] = isprime[1] = false; | |
for( ll i=2LL; i<=10000000LL; ++i ) if( isprime[i] ) { | |
for( ll j=i*i; j<=10000000LL; j+=i ) | |
isprime[j] = false; | |
} | |
while( scanf( "%d", &n )==1 ) { | |
// solve | |
if( !isprime[n] ) printf( "%d is not prime.\n", n ); | |
else { | |
if( isprime[revDig(n)] && n!=revDig(n) ) | |
printf( "%d is emirp.\n", n ); | |
else | |
printf( "%d is prime.\n", n ); | |
} | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽