Amonin

TRIPROSTIE

Dec 16th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. bool if_prime(int n) {
  6.     for (int i = 2; i <= sqrt(n); ++i) {
  7.         if (n % i == 0) {
  8.             return false;
  9.         }
  10.     }
  11.     return true;
  12. }
  13. int main() {
  14.     int n;
  15.     cin >> n;
  16.     int cnt = 0;
  17.     for (int i = pow(10, n - 1); i < pow(10, n); ++i) {
  18.         string num = to_string(i);
  19.         int count_primes = 0;
  20.         while (num.length() > 2) {
  21.             if (if_prime(stoi(num.substr(0, 3))) && to_string(stoi(num.substr(0, 3))).length() == 3) {
  22.                 ++count_primes;
  23.             }
  24.             num = num.substr(1);
  25.         }
  26.         if (count_primes == n - 2) {
  27.             ++cnt;
  28.         }
  29.     }
  30.     cout << cnt << endl;
  31.     //system("pause"); написано для работы в Visual Studio... если надо - убери //, если нет - сотри
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment