C. Plus and Square Root

链接:codeforces.com/group/1EzrFFyOc0/contest/716/problem/C

题型:构造

题意:起始数 x 为 2,在当前位置 i 可重复加上 i,直到 x 为 (( i + 1 )* k )^ 2  ( k = 1,2,3,4...)则来到位置  i+1 ,问每一步要加上多少次 i

题解:做的时候找到规律和构造式一样...但是因为爆ll没过。看了正派题解(https://blog.csdn.net/cmershen/article/details/52624592

自己再梳理一下:

在即将跳到下一个 level 的时刻,x 要满足以下条件

① x 为 i 的倍数 ,无论是加上 k 个 i 之前还是之后

② x 为 ( i + 1 ) 的倍数

③ x 为完全平方数

则设 x = i  ^ 2 * ( i + 1 ) ^ 2 ,由于递推,在刚抵达 i 时 x ' = i *( i - 1 ),所以 ans = (  x - x ' ) / i = i * i * i + 2 * i * i + 1 , 又 i = 1 时 起始值为 2 而非 i *( i - 1 ),所以要特判。

其他的满足条件的构造式都符合,解不唯一。

原因:迭代器设为int后爆ll,四次方爆ll,请记住。

代码:

/*找规律迭代器设为int后爆ll,四次方爆ll*/
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#define ll long long
#define PI 3.1415926535
using namespace std;
const int inf=2e5+;
//map<int,int> s;
bool cmp(const string& a,const string& b)
{
return a.length()<b.length();
}
map<char,int>mp;
int main()
{
ll n;
cin>>n;
ll t=;
for(ll i=;i<=n;i++)
{
ll temp;
temp=i*(i+);
ll ans;
//ans=(temp*temp-t)/i;
ans=temp/i*temp-t/i;
t=temp;
cout<<ans<<endl; }
}
/*构造,即规律的展开式*/
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#define ll long long
#define PI 3.1415926535
using namespace std;
const int inf=2e5+;
//map<int,int> s;
bool cmp(const string& a,const string& b)
{
return a.length()<b.length();
}
map<char,int>mp;
int main()
{
ll n;
cin>>n;
ll t=;
cout<<<<endl;
for(ll i=;i<=n;i++)
{
//ll temp;
//temp=i*(i+1);
ll ans;
//ans=(temp*temp-t)/i;
//ans=temp/i*temp-t/i;
ans=i*i*i+*i*i+;
//t=temp;
cout<<ans<<endl; } }

7.26-Codeforces Round #372 (Div. 2)的更多相关文章

  1. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  2. Codeforces Round #372 (Div. 2)

    Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...

  3. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #372 (Div. 2) C. Plus and Square Root

    题目链接 分析:这题都过了2000了,应该很简单..写这篇只是为了凑篇数= = 假设在第级的时候开方过后的数为,是第级的系数.那么 - 显然,最小的情况应该就是, 化简一下公式,在的情况下应该是,注意 ...

  5. Codeforces Round #372 (Div. 2) B

    Description ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists ...

  6. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))

    B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  8. Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))

    C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  10. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...

随机推荐

  1. Win系统的快捷键

    用了Macos觉得win系统不好用,其实不然,win也有很多方便的快捷键. win系统的快捷键: super/Alt+Tab键切换应用程序,而不是用鼠标点,切换多任务,super就是win win+D ...

  2. array_rand

    array_rand — 从数组中随机取出一个或多个单元 mixed array_rand ( array $array [, int $num = 1 ] ) 从数组中取出一个或多个随机的单元,并返 ...

  3. cf 1110 D

    哇真难啊,没注意到 可以开 dp[N][3][3]这种性质,也就是三个相同的顺子可以变成三个刻子,所以我们维护顺子的数目就不用超过三了,又因为每张牌i,只会被i-1,i-2,影响,所以额外开两维记录( ...

  4. 【C++语法基础】实验1

    实验内容: 题目:输入 1~7 的整数,如果输入的是 1~5,则输出“workday. Let’s work hard”:如果输入的是 6~7,则输出“weekend. Let’s have a re ...

  5. Django中URL有关

    django 模板中url的处理   在模板中直接添加‘/home’这样的链接是十分不推荐的,因为这是一个相对的链接,在不同网页中打开可能会返回不一样的结果. 所以推荐的是 1 <a href= ...

  6. iTextSharpH

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. linux命令:压缩解压打包工具大集合

    目录 (1)zip 压缩.解压缩及归档工具有很多,今天小编就整理几个大家较为常用的. compress gzip  bzip2 xz zip tar cpio 一.压缩.解压工具 用法 压缩 工具 压 ...

  8. 树莓派3 之 pi3Robot 控制系统配置

    需求 个人正在用Python写一个控制系统,技术选型是python3 + Flask + Mysql + Bootstrap.需要将这套系统直接部署到树莓派中. 代码地址:https://github ...

  9. C#4.0 HTTP协议无法使用TLS1.2的问题

    在发送HTTP请求前加入下行代码 ServicePointManager.SecurityProtocol = (SecurityProtocolType) | (SecurityProtocolTy ...

  10. JDBC事务(三)ThreadLocal绑定Connection

    处理一个请求即开启一个线程,在三层中,执行三层中的方法都是用的同一个线程. 我们开启一个事务,使用conn.setAutoCommit(false); conn应该属于ado层,不应该出现在servi ...