Codeforces Round #372 (Div. 1) A. Plus and Square Root 解题报告
来源:互联网 发布:模拟核弹爆炸软件 编辑:程序博客网 时间:2024/06/08 08:17
Codeforces Round #372 (Div. 1) A. Plus and Square Root 解题报告
A. Plus and Square Root
Codeforces Round #372 (Div. 1) A. Plus and Square Root
ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ’ + ’ (plus) and ‘’ (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.
When ZS the Coder is at level k, he can :
- Press the ’ + ’ button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k.
- Press the ‘’button. Let the number on the screen be x. After pressing this button, the number become . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m.
Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the ‘’ button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.
ZS the Coder needs your help in beating the game — he wants to reach level n + 1. In other words, he needs to press the ‘’ button n times. Help him determine the number of times he should press the ’ + ’ button before pressing the ‘’ button at each level.
Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.
题目大意:
当前你手中有一个数”2”(最开始的num)。从第一回合开始,在第m个回合中,你要对这个数做k次加法,使这个数变为k*m+num(num为上一回合操作完成后得到的数),并将其开方,得到一个新的num。要求这个新的num整除于m+1,同时输出每回合进行加法操作的次数k。
解题:
终于开始写csdn了,从大学开始真的是要努力了,关于codeforces的解题报告就从这道水题开始吧。
这道题一开始真的是没有什么头绪,虽然感觉是道数学题,可没什么想法,只好写了个小枚举找找灵感。大体就是枚举i,使((m+1)*(m+1)*i*i-num)%m==0这样的倒推枚举,不过如果这样做时间是肯定要爆的。
之后是看了一下m=10000左右的数据, 挺惊喜的发现大部分的最小的i都等于当前的回合数m,然后就直接把这个现象拿过来用重写了循环,只是m=1的时候需要特判一下。
代码如下:
#include <cstdio>using namespace std;long long n,k;int main(){scanf("%lld",&n);for(long long m=1;m<=n;m++) { if(m==1) k=2; else k=m*m*(m+2)+1; printf("%lld\n",k);}return 0; }
之后提交不出意外的一次过了,虽然是道水题。
证明:当k=m^2*(m+2)+1(m!=1)或2(m=1),得到的num一直符合题意
当m=1 时,k=2,新的num为2,成立。
假设m=x-1时成立,此时的num为(x-1)*x,当m=x时,若k=m^ 2* (m+2)+1,可求得新的num为x^2*(x+1)^2,整除于x+1。
综上,当k=m^2*(m+2)+1(m!=1)或2(m=1),得到的num一直符合题意。
- Codeforces Round #372 (Div. 1) A. Plus and Square Root 解题报告
- Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))
- Codeforces Round #372 (Div. 2) C. Plus and Square Root
- 【Codeforces Round #372 (Div. 2)】Codeforces 716C Plus and Square Root
- Codeforces Round #372 (Div. 2) C. Plus and Square Root 数论、方程、化简、推公式
- Codeforces Round #372 (Div. 2) -- C. Plus and Square Root(找规律枚举)
- Codeforces Round #372 (Div. 2) C. Plus and Square Root【二分】
- Codeforces Round #372 (Div. 2) C. Plus and Square Root —— 构造(数学题)
- codeforces round#372(div2 C) C. Plus and Square Root
- [Codeforces Round #372 DIV1A (CF715A)] Plus and Square Root
- Codeforces 715A Plus and Square Root
- codeforces 715A Plus and Square Root
- Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 解题报告
- 解题报告:Codeforces Round #381 (Div. 1)B. Alyona and a tree
- Codeforces Round #278 (Div. 1) 解题报告 A.B.
- Codeforces Round #283 (Div. 1)解题报告A.B.C.
- Codeforces Round #290 (Div. 1) 解题报告(A B)
- Codeforces Round #305 (Div. 1) A.B.C 解题报告
- 如何用视频编辑软件让彩色突出
- LeetCode------11. Container With Most Water
- [BZOJ4032] [HEOI2015] 最短不公共子串 - 后缀自动机,序列自动机,BFS
- Android 窗口管理服务WindowManagerService 简介
- python中tile()函数
- Codeforces Round #372 (Div. 1) A. Plus and Square Root 解题报告
- android SD卡浏览器
- 试题:基本算法题之【计算买股票的第n天每股股票值多少钱】
- 欢迎使用CSDN-markdown编辑器
- hdu--5878(hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001))
- 名厨android2.0项目总结
- Java集合---ArrayList的实现原理
- Thrift by Example
- 关于eclipse中复制项目