Superprime Rib</h1> </center>
Butchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer John ensures that a purchaser of his prime ribs gets really prime ribs because when sliced from the right, the numbers on the ribs continue to stay prime right down to the last rib, e.g.: </p>
7 3 3 1 </pre>The set of ribs denoted by 7331 is prime; the three ribs 733 are prime; the two ribs 73 are prime, and, of course, the last rib, 7, is prime. The number 7331 is called a superprime of length 4. </p>
Write a program that accepts a number N 1 <=N<=8 of ribs and prints all the superprimes of that length. </p>
The number 1 (by itself) is not a prime number. </p>
PROGRAM NAME: sprime</h3>
INPUT FORMAT</h3> A single line with the number N.
SAMPLE INPUT (file sprime.in) </h3>
4 </pre>
OUTPUT FORMAT</h3> The superprime ribs of length N, printed in ascending order one per line.
SAMPLE OUTPUT (file sprime.out)</h3>
2333 2339 2393 2399 2939 3119 3137 3733 3739 3793 3797 5939 7193 7331 7333 7393 </pre> /*
ID: hippo he
LANG: C++
TASK: sprime
*/
#include
#include
#include
#include
#include
using namespace std;
int N;
typedef pairNode;
void input(){
ifstream in("sprime.in");
in>>N;
in.close();
}
void output(vectorres){
ofstream out("sprime.out");
for (int it = 0; it < res.size(); it++) {
out<}
out.close();
}
bool isprime(int n)
{
if(n==2||n==3||n==5||n==7)return true;
else if(n==1||n%2==0)return false;
for(int i=3;i*i<=n;i+=2)
if(n%i==0)return false;
return true;
}
void bfs(int init,vector& res,int depth){
queueints;
Node ini;
ini.first=init;
ini.second=1;
ints.push(ini);
if(isprime(ini.first)&&ini.second==depth)
res.push_back(ini.first);
while(!ints.empty()){
Node tmp=ints.front();
ints.pop();
for (int i = 0; i < 5; i++) {
Node neb;
neb.first=tmp.first*10+2*i+1;
neb.second=tmp.second+1;
if(isprime(neb.first))
ints.push(neb);
if(isprime(neb.first)&&(neb.second)==depth)
res.push_back(neb.first);
}
if(tmp.second>depth)break;
}
}
void Bfs(vector&res,int depth){
bfs(2,res,depth);
bfs(3,res,depth);
bfs(5,res,depth);
bfs(7,res,depth);
}
int main(int argc, const char *argv[])
{
vectorres;
input();
Bfs(res,N);
output(res);
return 0;
}
</div>
分析预测模型在机器学习中的应用之线性回归
回归能做任何事情 Continue reading