• F. Vasilije Loves Number Theory


    Problem - F - Codeforces

    思路:分析一下题意,对于第一种操作来说,每次乘以x,那么n=n*x,然后问是否存在一个a使得gcd(n,a)=1并且n*a的约数个数等于n,有最大公约数等于1我们能够知道其实这两个数是互质的,所以d(n)*d(a)=d(n*a),那么就是要d(a)=n/d(n),所以n%d(n)一定要等于零,同时又因为当取模等于零时我们发现一定可以构造除一种方案,我们先选择一个与n互质的数x,然后让a=x^t,此时a共有(t+1)个约数,所以我们只需要让(t+1)=n/d(n)就能够构造出来,所以现在的问题变成了,我们能够判断n%d(n)等于0,我们知道一个因数个数的公式,就是所有质因数的个数加一的累乘,那么我们只需要维护n的所有质因数的个数即可,同时n并不能够直接乘以x,因为可能会乘的很大,所以我们在求出来d(n)之后,可以看看n与所有的x能否把d(n)消完,如果能消则代表可以

    1. // Problem: F. Vasilije Loves Number Theory
    2. // Contest: Codeforces - Codeforces Round 900 (Div. 3)
    3. // URL: https://codeforces.com/contest/1878/problem/F
    4. // Memory Limit: 256 MB
    5. // Time Limit: 2000 ms
    6. #include
    7. #include
    8. #include
    9. #define fi first
    10. #define se second
    11. #define i128 __int128
    12. using namespace std;
    13. typedef long long ll;
    14. typedef double db;
    15. typedef pair<int,int> PII;
    16. const double eps=1e-7;
    17. const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
    18. const long long int llINF=0x3f3f3f3f3f3f3f3f;
    19. inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
    20. while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
    21. inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
    22. inline void write(ll x,char ch) {write(x);putchar(ch);}
    23. void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
    24. bool cmp0(int a,int b) {return a>b;}
    25. template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
    26. template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
    27. void hack() {printf("\n----------------------------------\n");}
    28. int T,hackT;
    29. ll n,m,k;
    30. int pr[N],ttcnt;
    31. bool st[N];
    32. int cnt[N];
    33. map<int,int> tcnt;
    34. void init() {
    35. for(int i=2;i<=1000;i++) {
    36. if(!st[i]) pr[ttcnt++]=i;
    37. for(int j=0;pr[j]<=1000/i;j++) {
    38. st[pr[j]*i]=true;
    39. if(i%pr[j]==0) break;
    40. }
    41. }
    42. }
    43. void t_init(int x) {
    44. tcnt.clear();
    45. for(int i=0;i0;
    46. for(int j=0;j
    47. if(pr[j]>x) break;
    48. while(x%pr[j]==0) {
    49. cnt[pr[j]]++;
    50. x/=pr[j];
    51. }
    52. }
    53. if(x!=1) tcnt[x]++;
    54. }
    55. int get() {
    56. int res=1;
    57. for(int i=0;i1);
    58. for(auto &it:tcnt) res=res*(it.se+1);
    59. return res;
    60. }
    61. void change(int x,int &d) {
    62. int s=gcd(x,d);
    63. d/=s;
    64. }
    65. bool check(vector<int> &temp,int d) {
    66. change(n,d);
    67. for(int i=0;isize();i++) change(temp[i],d);
    68. if(d==1) return true;
    69. else return false;
    70. }
    71. void solve() {
    72. n=read();
    73. int q=read();
    74. t_init(n);
    75. vector<int> temp;
    76. while(q--) {
    77. int op=read();
    78. if(op==1) {
    79. int x=read();
    80. temp.push_back(x);
    81. for(int j=0;j
    82. if(pr[j]>x) break;
    83. while(x%pr[j]==0) {
    84. cnt[pr[j]]++;
    85. x/=pr[j];
    86. }
    87. }
    88. if(x!=1) tcnt[x]++;
    89. if(check(temp,get())) printf("YES\n");
    90. else printf("NO\n");
    91. }else if(op==2) {
    92. t_init(n);
    93. temp.clear();
    94. }
    95. }
    96. }
    97. int main() {
    98. init();
    99. // stin();
    100. // ios::sync_with_stdio(false);
    101. scanf("%d",&T);
    102. // T=1;
    103. while(T--) hackT++,solve();
    104. return 0;
    105. }

  • 相关阅读:
    搭建好自己的PyPi服务器后怎么使用
    CollectionUtils常用方法
    CSDN每日一题学习训练——Java版(逆序输出、Z 字形变换、输出每天是应该学习还是休息还是锻炼)
    专业英语第八章Communications and Networks测试题
    CADEditorX ActiveX 14.1.X
    2.23怎么在OrCAD原理图中显示与隐藏元器件的Value值?【OrCAD原理图封装库50问解析】
    JS面向对象的几种设计模式
    【NestJS系列】核心概念:Module模块
    Python 爬取单个网页所需要加载的URL地址和CSS、JS文件地址
    【算法系列 | 7】深入解析查找算法之—布隆过滤器
  • 原文地址:https://blog.csdn.net/zzzyyzz_/article/details/133754641