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. 6 关于plsql中文显示乱码问题

    打开plsql查看数据表时,会看到中文显示乱码问题 解决方案 输入下图所示语句并运行 在输入下图所示语句并运行,查看第一行和第九行是否对应 3)查看下环境变量的设置,查看是否有变量NLS_LANG,没 ...

  2. cmder 常用配置(包括默认管理员运行和解决中文乱码)

    简介 cmder是一个增强型命令行工具,不仅可以使用windows下的所有命令,更爽的是可以使用linux的命令,shell命令. 下载 官网地址:http://cmder.net/ 下载的时候,会有 ...

  3. 四、XML语言学习(1)

    XML语言 1.XML是什么?XML是指可扩展标记语言XML是指可扩展标记语言(eXtensible Markup Language),它是一种标记语言,很类似HTML.它被设计的宗旨是传输数据,而非 ...

  4. Python学习之旅(十四)

    Python基础知识(13):函数(Ⅳ) Python内置函数 1.abs:取绝对值 abs(-1) 1 2.all:把序列中的每一个元素拿出来做布尔运算,都为真则返回True,如果序列中有None. ...

  5. Mastering MariaDB 神秘的MariaDB 中文翻译版

    是某群的哥们义务翻译的,宣传一下,还没时间时间读,粗滤看了全部翻译完了300多页佩服 https://github.com/CMant/Mastering-MariaDB- 原地址:如果你需要读,请s ...

  6. 线程同步-Barrier类

    Barrier类:用于组织多个线程及时在某一个时刻碰面.并提供了一个回调函数,每次线程调用了SignalAndWait方法后该回调函数会被执行. 代码Demo: using System;using ...

  7. H/s:哈希率单位转换

    哈系率说明 挖矿能力是通过寻找矿工可以执行的地块的尝试次数来衡量的.每次尝试都包括创建一个唯一的块候选项,并通过SHA-256d(一种加密哈希函数)创建块候选项的摘要.或者,简而言之,哈希.由于这是一 ...

  8. laravel发布订阅

    1.php artisan make:command RedisSubscribe 在app console中会生成RedisSubscribe.php文件 <?php namespace Ap ...

  9. Java ee第五周作业

    Applet: Applet是采用Java编程语言编写的小应用程序,该程序可以包含在 HTML(标准通用标记语言的一个应用)页中,与在页中包含图像的方式大致相同. 含有Applet的网页的HTML文件 ...

  10. python-浅拷贝和深拷贝

    浅拷贝和深拷贝 浅拷贝 拷贝的副本共享内部对象的引用的拷贝为浅拷贝 举个栗子 list1 = [1, 2, [3, 4], (5, 6)] list2= list(list1) print(" ...