AT数学题一道

突然发神经想起来以前自己做的一道AT的题

https://atcoder.jp/contests/abc280/tasks/abc280_d

题目很简单:找到最小的N,使得N!为m的倍数

当时也是傻乎乎的暴力了,当然结果也是TLE

正确做法是这样的:

 

 

参考代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define int long long
 4 #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 5 int k;
 6 const int N=1000;
 7 /*int jc(int x)
 8 {
 9     int sum=1;
10     if(x==1)
11     return 1;
12     else
13     {
14         return x*jc(x-1);
15     }
16 }*/
17 void solved()
18 {
19     for(int i=2;i<=2e6+10;i++)
20     {
21         k=k/__gcd(i,k);
22         if(k==1)
23         {
24             cout<<i<<endl;
25             return ;
26         }
27     }
28     cout<<k<<endl;
29 }
30 signed main()
31 {
32     IOS;
33     cin>>k;
34     int sum=2;
35         /*if(sum*i%k==0)
36         {
37             cout<<i<<endl;
38             break;
39         }
40         else
41         {
42             sum=sum*i;
43         }*/
44         solved();
45     return 0;
46 }

 

posted @ 2023-01-12 16:59  江上舟摇  阅读(15)  评论(0编辑  收藏  举报