ACM-ICPC 2018南京赛区网络预选赛

A题:An Olympian Math Problem

可以发现最终的答案就是n-1

 1 #include <iostream>
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 int main()
 6 {
 7     int t;
 8     ll n;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%lld",&n);
13         printf("%lld
",n-1);
14     }
15     return 0;
16 }
View Code

B题:The writing on the wall


C题:GDY


D题:Jerome's House


E题:AC Challenge


F题:An Easy Problem On The Trees


G题:Lpl and Energy-saving Lamps


H题:Set


I题:Skr


J题:Sum

我们可以发现如果一个数可以写成n=p1a1p2a2p3a3....pmam       

如果某一个a大于2,那么f[n]=0

如果a都是1,那么f[n]=2m

如果有cnt个a是2,其他都是1,那么f[n]=2m-cnt

我们可以用线性筛,可惜比赛时不会写。。。

赛后参考大佬们的代码https://blog.csdn.net/qq_25576697/article/details/82319883

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 const int N=20000007;
 5 int vis[N+5],prime[N+5],ans[N+5],f[N+5];
 6 void init()
 7 {
 8     vis[1]=1;
 9     f[1]=1;
10     int cnt=0;
11     for(int i=2;i<=N;i++)
12     {
13         if(!vis[i])
14         {
15             prime[++cnt]=i;
16             f[i]=2;
17         }
18         for(int j=1;j<=cnt&&i*prime[j]<N;j++)
19         {
20             int tmp=i*prime[j];
21             vis[tmp]=1;
22             if(i%prime[j])
23                 f[tmp]=f[i]*2;
24             else if(i%(prime[j]*prime[j])==0)
25                 f[tmp]=0;
26             else
27             {
28                 f[tmp]=f[tmp/prime[j]/prime[j]];
29                 break;
30             }
31         }
32     }
33     for(int i=1;i<=N;i++)
34         ans[i]=ans[i-1]+f[i];
35 }
36 int main()
37 {
38     init();
39     int t,n;
40     scanf("%d",&t);
41     while(t--)
42     {
43         scanf("%d",&n);
44         printf("%d
",ans[n]);
45     }
46     return 0;
47 }
View Code

K题:The Great Nim Game


L题:Magical Girl Haze


如有错误,请指正,感谢!
原文地址:https://www.cnblogs.com/scott527407973/p/9583041.html