worldline
思路:
第1e18个数。。。。。。
明显是个预处理后查询的题目,怎么存1e18???
大胆猜测数字肯定不多。
打表打表!!!
发现没有1e9级别的数,自然之后的也不会有了。
打表程序
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
# define rep(i, s, t) for ( register int i = s, l = t ; i <= l ; ++ i )
using namespace std ;
inline bool isprime ( int x ) {
int qq = sqrt ( x ) ;
for(int i=2; i<=qq; ++i)
if(x % i == 0) return 0;
return 1 ;
}
const int d[] = { 1, 3, 7, 9 };
vector<int> prime ;
queue<int> q ;
inline void Bfs ( ) {
prime.push_back ( 2 );
prime.push_back ( 3 );
prime.push_back ( 5 );
prime.push_back ( 7 );
q.push ( 2 );
q.push ( 3 );
q.push ( 5 );
q.push ( 7 );
for( ; !q.empty ( ); ) {
int u = q.front(); q.pop();
for(int i=0; i<4; ++i) {
int v = u * 10 + d [i] ;
if( isprime ( v ) ){
if(v <= 73939133) prime.push_back ( v ), q.push ( v ) ;
if(v > 73939133 && d [i] == 9) return ;
}
}
}
}
int main ( ) {
freopen ( "out.txt", "w", stdout );
Bfs();
sort(prime.begin(), prime.end());
int cnt( 0 ) ;
for ( vector < int > :: iterator it = prime.begin ( ) ; it != prime.end ( ) ; ++ it ) {
printf( "a [%d] = %d ;\n", ++ cnt, *it );
}
}
表
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std ;
int a[200010];
int main(){
a[1] = 2;
a[2] = 3;
a[3] = 5;
a[4] = 7;
a[5] = 23;
a[6] = 29;
a[7] = 31;
a[8] = 37;
a[9] = 53;
a[10] = 59;
a[11] = 71;
a[12] = 73;
a[13] = 79;
a[14] = 233;
a[15] = 239;
a[16] = 293;
a[17] = 311;
a[18] = 313;
a[19] = 317;
a[20] = 373;
a[21] = 379;
a[22] = 593;
a[23] = 599;
a[24] = 719;
a[25] = 733;
a[26] = 739;
a[27] = 797;
a[28] = 2333;
a[29] = 2339;
a[30] = 2393;
a[31] = 2399;
a[32] = 2939;
a[33] = 3119;
a[34] = 3137;
a[35] = 3733;
a[36] = 3739;
a[37] = 3793;
a[38] = 3797;
a[39] = 5939;
a[40] = 7193;
a[41] = 7331;
a[42] = 7333;
a[43] = 7393;
a[44] = 23333 ;
a[45] = 23339 ;
a[46] = 23399 ;
a[47] = 23993 ;
a[48] = 29399 ;
a[49] = 31193 ;
a[50] = 31379 ;
a[51] = 37337 ;
a[52] = 37339 ;
a[53] = 37397 ;
a[54] = 59393 ;
a[55] = 59399 ;
a[56] = 71933 ;
a[57] = 73331 ;
a[58] = 73939 ;
a[59] = 233993;
a[60] = 239933;
a[61] = 293999;
a[62] = 373379;
a[63] = 373393;
a[64] = 593933;
a[65] = 593993;
a[66] = 719333;
a[67] = 739391;
a[68] = 739393;
a[69] = 739397;
a[70] = 739399;
a[71] = 2339933;
a[72] = 2399333;
a[73] = 2939999;
a[74] = 3733799;
a[75] = 5939333;
a[76] = 7393913;
a[77] = 7393931;
a[78] = 7393933;
a[79] = 23399339;
a[80] = 29399999;
a[81] = 37337999;
a[82] = 59393339;
a[83] = 73939133;
int T; scanf("%d", &T);
while ( T-- ) {
int n; scanf("%d", &n);
printf("%d\n", a[n]);
}
}