?? usaco_sprime.cpp
字號:
/*
ID:wangyuc2
PROG:sprime
LANG:C++
*/
#include <iostream>
#include <fstream>
#include <memory.h>
#include <cmath>
#include <algorithm>
using namespace std;
bool isprime(int a)
{
for(int i=2;i<=(int)sqrt(a);i++)
if(a%i == 0) return false;
return true;
}
int main()
{
ifstream fin ("sprime.in");
ofstream fout ("sprime.out");
int a[10000];
int b[9]={0,10,100,1000,10000,100000,1000000,10000000,100000000};
int i,j,k,length,current=10;
a[0]=2; a[1]=3; a[2]=5; a[3]=7;
i=0;j=3;
fin>>length;
// j=1;
if(length==1) {for(k=0;k<4;k++) fout<<a[k]<<endl;}
else{
while(a[i]<b[length-1])
{
if(a[i]<b[length-2])
{
for(k=0;k<10;k++)
{
if(isprime(a[i]*10+k))
{
a[++j]=a[i]*10+k;
}
}
}
else
{
for(k=0;k<10;k++)
{
if(isprime(a[i]*10+k))
{
a[++j]=a[i]*10+k;
fout<<a[j]<<endl;
}
}
}
i++;
}
}
// system("PAUSE");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -