PlanttPastes

euler 41

Jun 25th, 2026
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool prime(int n) {
  5.     for (int i = 2; i * i <= n; i++) if (!(n % i)) return false;
  6.     return true;
  7. }
  8.  
  9. signed main() {
  10.     ios::sync_with_stdio(0);
  11.     cin.tie(0); cout.tie(0);
  12.     string n = "7654321";
  13.     do {
  14.         if (prime(stoi(n))) {
  15.             cout << n;
  16.             break;
  17.         }
  18.     } while (prev_permutation(n.begin(), n.end()));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment