https://www.wechall.net/challenge/training/prime_factory/index.php
代码:
#include <iostream>
using namespace std;
int isPrime(int k)
{
int j;
for ( j=2; j<k; j++ )
{
if(k%j==0) // 如果不为素数返回0
{
return 0;
}
}
return 1; // 反之则返回1
}
int main()
{
int count = 0;
int num = 1000000;
while(count != 2){
int arr[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
int i = 0,j = 0;
int sum = 0;
int temp = num;
while(temp != 0){
arr[i] = temp % 10;
temp = temp / 10;
i++;
}
while(arr[j] != -1){
sum += arr[j];
j++;
}
if(isPrime(num) == 1 && isPrime(sum) == 1){
cout << num << endl;
count++;
}
num++;
}
return 0;
}
Answer:10000331000037