codeforces715A Plus and Square Root (构造)
来源:互联网 发布:华为 培训 入职 知乎 编辑:程序博客网 时间:2024/06/11 05:42
题意:
初始数为2,初始等级为1,有如下两种操作:
1. 这个数加上当前等级k
2. 这个数开根号,但前提是这个数是完全平方数且开完根号后为下一等级(k+1)的倍数。该操作之后等级+1
要求对于2, ......, n+1等级输出从上一等级到该等级的第一个操作的次数
答案不唯一,输出任一一个即可
类型:
数学构造题
构造方法:
假设当前等级为k,那我们只需要第一种操作到达(k * (k + 1)) ^ 2就可以了,然后第二种操作转换成k * (k + 1)
构造过程可以很容易通过数学归纳法证明,此处简单证明一下:
等级1时需要步数2为特殊情况
设当前等级为k(k >= 2),则当前数字为(k - 1) * k,那么我们一定可以通过第一步操作到达k * k * (k + 1) * (k + 1),
需要次数为k * (k + 1) * (k + 1) - (k - 1)
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;int main() { LL n; scanf("%I64d", &n); n++; LL u = 2; for (LL i = 2; i <= n; i++) { LL v = (i - 1) * i * i; printf("%I64d\n", v - u / (i - 1)); u = (i - 1) * i; } return 0;}
0 0
- codeforces715A Plus and Square Root (构造)
- codeforces715A-Plus and Square Root
- CF 715A Plus and a square root(数学构造)
- codeforces716c Plus and Square Root
- Codeforces 715A Plus and Square Root
- codeforces 715A Plus and Square Root
- Codeforces Round #372 (Div. 2) C. Plus and Square Root —— 构造(数学题)
- Codeforces 716C C. Plus and Square Root
- code forces round 372 div2.c Plus and Square Root
- codeforces round#372(div2 C) C. Plus and Square Root
- 【33.17%】【Codeforces 715A】Plus and Square Root
- Codeforces Round #372 (Div. 2) C. Plus and Square Root
- CodeForces 715A. Plus and Square Root(数学,脑洞题)
- [Codeforces Round #372 DIV1A (CF715A)] 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) -- C. Plus and Square Root(找规律枚举)
- Codeforces Round #372 (Div. 1) A. Plus and Square Root 解题报告
- DialogFragment 创建对话框
- 编译spark1.6.1源码
- 剑指offer-矩形覆盖
- JAVA学习总结之线程概述
- java-虚拟机类加载机制
- codeforces715A Plus and Square Root (构造)
- 设置checkbox的大小
- android studio 错误Error:Unable to start the daemon process.
- 进程通信--信号量,共享内存
- 学习笔记 Tianmao 篇 materialRefreshLayout 下拉刷新 控件的使用
- Mybatis-Spring-注入映射器
- ECMAScript6标准编程风格,读懂ECMAScript规格
- iOS 10适配以及Xcode8兼容问题总结
- python异常 详解(续)