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. Tomb Raider

    Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her ...

  2. react使用BrowserRouter打包后,刷新页面出现404

    文档 https://gkedge.gitbooks.io/react-router-in-the-real/content/apache.html nginx nginx.conf server { ...

  3. 12:Css3的概念和优势

    12:Css3的概念和优势 CSS3是css技术的升级版本,CSS3语言开发是朝着模块化发展的.以前的规范作为一个模块实在是太庞大而且比较复杂,所以,把它分解为一些小的模块,更多新的模块也被加入进来. ...

  4. juqery 回车事件 回车操作 回车搜索

    html <form class="search_wrap" method="post" action=""> <div ...

  5. python全栈开发 * 13知识点汇总 * 180619

    13 迭代器和⽣成器一.迭代器 1.以通过dir函数来查看类中定义好的所有⽅法 2.__iter__ 用来获取当前对象的迭代器 3.__next__ 获取可迭代对象的元素s="我爱吃火锅&q ...

  6. linux ---部署django项目篇

    uWSGI + nginx+ django + virtualenv + supervisor发布web服务器 项目部署步骤 1.项目准备阶段 1.准备项目代码,从本地拷贝 2.将项目上传到linux ...

  7. dokuwiki 安装配置

    dokuwiki如果在用户注册的时候,发生"发送密码邮件时产生错误.请联系管理员!",那么需要配置sendmail. 在linux平台下,参考这个帖子https://www.dok ...

  8. 内置委托func

    1.p=>p.CTName,其中p是此委托入参,p.CTName是返回值 2. 3.调用委托的方法

  9. 基于Windows的git代码统计工具GitStats

    参考: https://blog.csdn.net/windfromthesouth/article/details/72961525

  10. 010 Editor - Binary Templates

        010 Editor是一款非常强大的文本/十六进制编辑器,除了文本/十六进制编辑外,还包括文件解析.计算器.文件比较等功能,但它真正的强大之处还在于文件的解析功能.我们可以使用010Edito ...