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",n-1);
14     }
15     return 0;
16 }


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\n",ans[n]);
45     }
46     return 0;
47 }


K题:The Great Nim Game


L题:Magical Girl Haze



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

原文地址:https://www.cnblogs.com/scott527407973/p/9583041.html

时间: 2024-11-02 23:24:16

ACM-ICPC 2018南京赛区网络预选赛的相关文章

ACM-ICPC 2018 南京赛区网络预赛 E题

ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has s

ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树

目录 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 题意 思路 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the

ACM-ICPC 2018 南京赛区网络预赛 J.Sum

Sum A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square number. Some integers could be decomposed into

ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

262144K There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance c_ici?. Haze is a Magical Girl that lives in City 11, she can choose no more than KK roads and make their distances

计蒜客 ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem-数学公式题

A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him.

ICPC 2018 徐州赛区网络赛

ACM-ICPC 2018 徐州赛区网络赛 ?去年博客记录过这场比赛经历:该死的水题 ?一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. ? ? D. Easy Math 题意: ? 给定 \(n\), \(m\) ,求 \(\sum _{i=1}^{m} \mu(in)\) .其中 $ 1 \le n \le 1e12$ , $ 1 \le m \le 2e9$ ,\(\mu(n)\) 为莫比乌斯函数. ? 思路: ? 容易知道,\(i\) 与 \(n\) 不互质时, \(\m

线性素数筛 ACM-ICPC 2018 南京赛区网络预赛 J Sum

https://www.jisuanke.com/contest/1555?view=challenges 题意: 题解:写完都没发现是个积性函数233 想法就是对x分解质因数,f(x)就是2^k,其中k是x分解结果中次数为一的质因子个数.如果有某个次数大于等于3,f(x)==0; 这样明显会TLE 所以就想一个递推的方法. 于是魔改了一下线性筛. #include<iostream> #include<cstdlib> #include<cstdio> #includ

ACM-ICPC 2018 南京赛区网络预赛 - C GDY (模拟)

诶,比赛时差一点就debug出来了 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int mod = 14; map<int,int> vz[205]; LL ans[205]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.tx

ACM-ICPC 2018 南京赛区网络预赛 做题记录

比赛的时候被J题卡常然后B题自闭最后G题没调完 5题gg 现在补题进度:6/12 A. 题解: 高考数学题,裂项完之后答案就是n!-1 (n!)%n=0,所以就是n-1 1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int T; 5 ll n; 6 int main() 7 { 8 cin>>T; 9 while(T--) 10 { 11 cin>>n; 12 cout