CSDN同步

原题链接

简要题意:

多组数据,问能否把 \(n\) 分为 \(k\) 个 不同的 正奇数之和。

盲猜数学结论题。

只要考虑两个问题:

  1. \(n\) 的大小是否足够。

  2. \(n\) 的奇偶性是否满足。

对于第 \(1\) 条,最小的 \(k\) 个 不同的 正奇数之和为 \(k^2\).(这都不知道,建议重学小学数学)

所以,\(n \geq k^2\) 才可能有解。

对于第 \(2\) 条,因为 \(k\) 个正奇数与 \(k\) 的奇偶性相同,所以必须满足:

\[n \equiv k \pmod 2
\]

这两条同时满足即有解,否则无解。

为什么呢?

考虑一种拆分:

\[1 + 3 + 5 + ... + (2k-3) + p = n
\]

即前 \(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 题解的更多相关文章

  1. LeetCode Sum of Two Integers

    原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...

  2. [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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 【LeetCode】Sum of Two Integers

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  7. 每天一道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 ...

  8. 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 - ...

  9. 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 -. ...

随机推荐

  1. 《自动化平台测试开发-Python测试开发实战》第2次印刷

    书籍货源比较紧张.紧张啊,如此短的时间,已经第2次印刷.第2次印刷. 第2次印刷. 同时该书已确认与台湾出版社合作翻译成繁体版,甚至有可能与国外出版社合作翻译成英文版. 2018年7月 第1次印刷 2 ...

  2. 每日背单词 - Jun.

    6月1日裸辞,计划休息到端午节后,这段时间玩的确实很开心,每天和朋友一起吹灯拔蜡:好不自在,可惜假期马上结束了,从今天开始恢复学习状态. 2018年6月1日 - 2018年6月14日 辞职休假 201 ...

  3. yii框架通过控制台命令创建定时任务

    假设Yii项目路径为 /home/apps 1. 创建文件 /home/apps/web/protected/commands/console.php $yii = '/home/apps/frame ...

  4. android逆向---charles抓包

    手机与电脑处于同一网络环境,且正确设置代理后,charles显示CONNECT失败,提示信息SSL handshake with client failed: An unknown issue occ ...

  5. ASP.NET Core 反向代理部署知多少

    引言 最近在折腾统一认证中心,看到开源项目IdentityServer4.Admin集成了IdentityServer4和管理面板,就直接拿过来用了.在尝试Nginx部署时遇到了诸如虚拟目录映射,请求 ...

  6. Java大浮点数精度

    BigDecimal 精度问题 BigDecimal舍入模式 ROUND_DOWN 向零舍入. 即1.55 变为 1.5 , -1.55 变为-1.5 ROUND_UP 向远离0的方向舍入 即 1.5 ...

  7. kafka知识整理

    title: kafka知识整理 date: 2019-06-18 10:59:46 categories: MQ tags: kafka --- 转载自:https://www.cnblogs.co ...

  8. Python读取和写入文件

    1 从文件中读取数据 1.1 读取整个文件 创建名为test的txt文本文件,添加内容如下所示: 123456789023456789013456789012 实现代码: with open('tes ...

  9. Python基础-两个乒乓球队进行比赛,各出三人。

    两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. L1 = [ ...

  10. java线程间的协作

    本次内容主要讲等待/通知机制以及用等待/通知机制手写一个数据库连接池. 1.为什么线程之间需要协作 线程之间相互配合,完成某项工作,比如:一个线程修改了一个对象的值,而另一个线程感知到了变化,然后进行 ...