PlanttPastes

euler 34

Jun 25th, 2026
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. constexpr int f[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
  5. bool ok(int n) {
  6.     int b = n;
  7.     while (n) {
  8.         b -= f[n % 10];
  9.         n /= 10;
  10.     }
  11.     return !b;
  12. }
  13.  
  14. signed main() {
  15.     ios::sync_with_stdio(0);
  16.     cin.tie(0); cout.tie(0);
  17.     int64_t s = 0;
  18.     // do 40585 pa ke zakoci, najbolje samo soberi gi dvata broja lol
  19.     for (int i = 3; i < 40586; i++) {
  20.         if (ok(i)) {
  21.             s += i;
  22.             cerr << i << '\n';
  23.         }
  24.     }
  25.     cout << s;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment