WeChall Prime Factory (Training, Math)

https://www.wechall.net/challenge/training/prime_factory/index.php

WeChall Prime Factory (Training, Math)

 

 

 代码:

#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;
}

WeChall Prime Factory (Training, Math)

 

 Answer:10000331000037

WeChall Prime Factory (Training, Math)

上一篇:48 Express脚手架框架开发


下一篇:精读《useEffect 完全指南》