Advertisement
Dmaxiya

混乘数字 参考代码

Apr 8th, 2025
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. int ans;
  6. LL p[20];
  7.  
  8. LL getHash(int x, int y) {
  9.     LL ret = 0;
  10.     while (x != 0) {
  11.         ret += p[x % 10];
  12.         x /= 10;
  13.     }
  14.     while (y != 0) {
  15.         ret += p[y % 10];
  16.         y /= 10;
  17.     }
  18.     return ret;
  19. }
  20.  
  21. bool judge(int x) {
  22.     LL xHash = getHash(x, 0);
  23.     for (int i = 2; i <= x / i; ++i) {
  24.         if (x % i == 0) {
  25.             if (getHash(i, x / i) == xHash) {
  26.                 return true;
  27.             }
  28.         }
  29.     }
  30.     return false;
  31. }
  32.  
  33. int main() {
  34. #ifdef ExRoc
  35.     freopen("test.txt", "r", stdin);
  36. #endif // ExRoc
  37.     ios::sync_with_stdio(false);
  38.  
  39.     p[0] = 1;
  40.     for (int i = 1; i < 10; ++i) {
  41.         p[i] = p[i - 1] * 10;
  42.     }
  43.     for (int i = 1; i <= 1000000; ++i) {
  44.         if (judge(i)) {
  45.             ++ans;
  46.         }
  47.     }
  48.     cout << ans << endl;
  49. //    cout << 590 << endl;
  50.  
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement