PlanttPastes

euler 27

Jun 25th, 2026
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool prime(int n) {
  5.     if (n < 2) return false;
  6.     for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
  7.     return true;
  8. }
  9. signed main() {
  10.     ios::sync_with_stdio(0);
  11.     cin.tie(0); cout.tie(0);
  12.     int maxn = 0, ma, mb;
  13.     for (int a = -999; a < 1000; a++) {
  14.         for (int b = -1000; b < 1001; b++) {
  15.             int n = 0;
  16.             while (prime(n * n + a * n + b)) ++n;
  17.             if (n > maxn) {
  18.                 maxn = n;
  19.                 ma = a;
  20.                 mb = b;
  21.             }
  22.         }
  23.     }
  24.     cerr << ma << ' ' << mb << endl;
  25.     cout << ma * mb;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment