• Codeforces Round 900 (Div. 3) F


    gcd(a, n) = 1并且d(a * n) == n

    a、n互质说明a与n在>=2范围内没有公共因子,d(a * n) = d(a) * d(n)

    d(a)可以是任意数,只要a的因子是n中没有的就行

    所以问题转化为d(n)能否整除n,由于n可能很大不能直接算

    这种时候可以将n分解为质因数的形式,看能否被d(n)除尽 

    只要d(n)的质因数形式上的每一项的指数都小于等于n的质因数形式上的指数就说明可以除尽。

    另外gcd(a, n)!=1时d(a * n)不一定等于d(a) * d(n)

    所以应该只能枚举n的质因数来判断了

    最坏情况是1000个2^p,最大在2^20次方左右,20存1000次是2e4,这1000次每次都要遍历完

    最坏复杂度大约在1000 * 2e4 = 2e7左右,分解质因数复杂度为1000*sqrt(1e6)

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef pair<int, int> PII;
    6. typedef long long ll;
    7. typedef long double ld;
    8. void solve()
    9. {
    10. int n, q;
    11. cin >> n >> q;
    12. map<int, int>mp;
    13. ll num = 1;
    14. for(int i = 2; i * i <= n; i ++)
    15. {
    16. if(n % i == 0)
    17. {
    18. int c = 0;
    19. while(n % i == 0)
    20. {
    21. n /= i;
    22. c ++;
    23. }
    24. mp[i] += c;
    25. num *= c + 1;//n的因子个数
    26. }
    27. }
    28. if(n > 1)
    29. {
    30. mp[n] ++;
    31. num *= 2;
    32. }
    33. map<int, int> mp_t = mp;
    34. ll num_t = num;
    35. while(q --)
    36. {
    37. int op;
    38. cin >> op;
    39. if(op == 1)
    40. {
    41. int x;
    42. cin >> x;
    43. for(int i = 2; i * i <= x; i ++)
    44. {
    45. if(x % i == 0)
    46. {
    47. int c = 0;
    48. while(x % i == 0)
    49. {
    50. x /= i;
    51. c ++;
    52. }
    53. num /= mp[i] + 1;
    54. mp[i] += c;
    55. num *= mp[i] + 1;
    56. }
    57. }
    58. if(x > 1)
    59. {
    60. num /= mp[x] + 1;
    61. mp[x] ++;
    62. num *= mp[x] + 1;
    63. }
    64. int t = num;
    65. for(auto item : mp)
    66. {
    67. int x = item.first, y = item.second;
    68. while(y > 0 && t % x == 0)
    69. {
    70. y --;
    71. t /= x;
    72. }
    73. }
    74. if(t == 1)cout << "YES" << endl;
    75. else cout << "NO" << endl;
    76. }
    77. else
    78. {
    79. mp = mp_t;
    80. num = num_t;
    81. }
    82. }
    83. cout << endl;
    84. }
    85. int main()
    86. {
    87. IOS
    88. int _;
    89. cin >> _;
    90. while(_ --)
    91. {
    92. solve();
    93. }
    94. return 0;
    95. }

  • 相关阅读:
    如何在Windows 10上更改默认系统字体,这里有详细步骤
    【Liunx】进程概念,查看进程,进程调用,创建子进程
    【深入浅出Spring6】第七期——使用JDBC模板与代理模式
    docker-io, docker-ce, docker-ee 区别
    CSS3 grid 网格/栅格布局
    k8s-service详解
    二进制的形式在内存中绘制一个对象实例
    (尚硅谷)2021 版 SpringMVC 教程笔记
    智能化推送服务MobPush产品简介
    Map集合
  • 原文地址:https://blog.csdn.net/a1695574118/article/details/133363616