CF1327A Sum of Odd Integers 题解
简要题意:
多组数据,问能否把 \(n\) 分为 \(k\) 个 不同的 正奇数之和。
盲猜数学结论题。
只要考虑两个问题:
\(n\) 的大小是否足够。
\(n\) 的奇偶性是否满足。
对于第 \(1\) 条,最小的 \(k\) 个 不同的 正奇数之和为 \(k^2\).(这都不知道,建议重学小学数学)
所以,\(n \geq k^2\) 才可能有解。
对于第 \(2\) 条,因为 \(k\) 个正奇数与 \(k\) 的奇偶性相同,所以必须满足:
\]
这两条同时满足即有解,否则无解。
为什么呢?
考虑一种拆分:
\]
即前 \(k-1\) 个正奇数加上另一个奇数。
如果 \(n\) 同时满足上两条,则显然存在这样的拆分,且 \(p \geq 2 \times k - 1\),也不存在重复。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){char ch=getchar();int f=1;while(ch<'0' || ch>'9') {if(ch=='-') f=-f; ch=getchar();}
ll x=0;while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
int main(){
ll T=read(),n,k; while(T--) {
n=read(),k=read();
if(n<k*k || (n-k)&1) puts("NO");
else puts("YES");
} //别忘了,k*k会爆int,开上 long long
return 0;
}
CF1327A Sum of Odd Integers 题解的更多相关文章
- LeetCode Sum of Two Integers
原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...
- [LeetCode] Sum of Two Integers 两数之和
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- Nim Game,Reverse String,Sum of Two Integers
下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...
- LeetCode 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- leetcode371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- 【LeetCode】Sum of Two Integers
问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...
- 每天一道LeetCode--371. Sum of Two Integers
alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...
- 371. Sum of Two Integers -- Avota
问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...
- Leetcode 371: Sum of Two Integers(使用位运算实现)
题目是:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...
随机推荐
- Proto3:Techniques
本文描述处理Protocol Buffer常用到的一些设计模式.你也可以给Protocol Buffers discussion group发送设计或使用问题. 流式多条消息 如果你想将多个消息写入到 ...
- 苹果iPhone9、小米7…当曝光成为一门生意就没那么好玩了
大众最乐此不疲的,当然就是以熊熊燃烧的八卦之心,去挖掘各种或为隐私,或为未知的那些事儿.为此,狗仔队.曝光人士等就受到了追捧.当然,也有对他们的各种嘲讽--而在智能手机行业,各种曝光更是乐此不疲的上演 ...
- arm-eabi-addr2line工具跟踪Android调用堆栈
使用arm-eabi-addr2line工具跟踪Android调用堆栈作者:liangshengyang转自:http://www.linuxidc.com/Linux/2011-01/31803.h ...
- AAAI |如何保证人工智能系统的准确性?
|如何保证人工智能系统的准确性?" title="AAAI |如何保证人工智能系统的准确性?"> 注:本文译自AI is getting smarter; ...
- Android中使用AsyncTask
>##今天写作业用到了AnsyncTask,记录一下自己的使用情况 >###1.Android.os.AsyncTask类 > 1.AsyncTask类对线程间通讯进行了包装,我们 ...
- hue初识
Hue Web应用的架构 Hue 是一个Web应用,用来简化用户和Hadoop集群的交互.Hue技术架构,如下图所示,从总体上来讲,Hue应用采用的是B/S架构,该web应用的后台采用python编程 ...
- Python几个简单实用的模块
今天整理了下,工作中常用的一些高阶函数,后面持续更新...... 一.collections 二.itertools 三.functools
- mysql 存储过程 执行存储过程修改了表中所有行的信息
存储过程中的where条件语句,如果传入的参数和表字段名相同,存储过程就会把这个约束条件忽略.小结:存储过程中传递的参数名不要和字段名相同.特别是修改.删除等操作,可能会对整张表产生影响.后果会很严重 ...
- overflow-y:auto/hidden/scroll和overflow-x:visible组合渲染异常
最近做项目想做一个这样的效果:就是我想要内部div x轴溢出div则显示y轴溢出div则出现滚动条于是用到了overflow-y 和 overflow-x 这个css属性原来以为css中直接设置就ok ...
- 看过无数Java GC文章,这5个问题你也未必知道!
看过无数Java GC文章,这6个问题你也未必知道! 读者朋友们可能已经看过太多关于Java垃圾回收相关的文章,如果没有,墙裂安利大家看下面这篇: 看完这篇垃圾回收,和面试官扯皮没问题了 本文不再重复 ...