Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- bool if_prime(int n) {
- for (int i = 2; i <= sqrt(n); ++i) {
- if (n % i == 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- int n;
- cin >> n;
- int cnt = 0;
- for (int i = pow(10, n - 1); i < pow(10, n); ++i) {
- string num = to_string(i);
- int count_primes = 0;
- while (num.length() > 2) {
- if (if_prime(stoi(num.substr(0, 3))) && to_string(stoi(num.substr(0, 3))).length() == 3) {
- ++count_primes;
- }
- num = num.substr(1);
- }
- if (count_primes == n - 2) {
- ++cnt;
- }
- }
- cout << cnt << endl;
- //system("pause"); написано для работы в Visual Studio... если надо - убери //, если нет - сотри
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment