Codeforce 1327A - Sum of Odd Integers

Example
input
6
3 1
4 2
10 3
10 2
16 4
16 5
output
YES
YES
NO
YES
YES
NO
解题思路:首先我们应该知道:偶数个奇数相加一定是偶数,奇数个奇数相加一定是奇数,所以对于给出的n和k,如果n是偶数,k是奇数,或者n是奇数,k是偶数,n和k不是同奇同偶,则n一定不可能由k个奇数相加得到。所以我们先判断n和k是否同为奇数(偶数),这是要考虑的第一点,第二点,k个奇数有一个最小值,如果k=4,则k个不同的奇数最小值为1+3+5+7=16,如果n的值<=16,n也不可能由k个奇数相加得到,k=1时候,最小值是1,k等于2时,最小值4,k等于3时,最小值9,通过观察可以发现,k的最小值就是k*k。所以判断一下n是否大于k的平方即可。ac代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
//freopen("in.txt", "r", stdin);
int t; cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
if ((n & 1) != (k & 1))
cout << "No" << endl;
else {
if (n >= k * k)cout << "Yes" << endl;
else cout << "No" << endl;
}
}
}
Codeforce 1327A - Sum of Odd Integers的更多相关文章
- CF1327A Sum of Odd Integers 题解
原题链接 简要题意: 多组数据,问能否把 \(n\) 分为 \(k\) 个 不同的 正奇数之和. 盲猜数学结论题. 只要考虑两个问题: \(n\) 的大小是否足够. \(n\) 的奇偶性是否满足. 对 ...
- [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 ...
- LeetCode Sum of Two Integers
原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...
- 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 -. ...
随机推荐
- 用友U8和旺店通·企业奇门单据接口对接
用友U8和旺店通·企业奇门单据接口对接 对接系统旺店通·企业奇门 旺店通是北京掌上先机网络科技有限公司旗下品牌,国内的零售云服务提供商,基于云计算SaaS服务模式,以体系化解决方案,助力零售企业数字化 ...
- VM离线安装Centos 8以及配置
一.安装 1.预装准备 1.1. 硬件准备 物理内存:2G以上(这里指系统搭建所需占用空间) 物理外存:20G(这里指系统搭建所需占用空间) 1.2. 环境搭建准备 Window10系统电脑一台.Vm ...
- [CF1830D] Mex Tree
题目描述 You are given a tree with $ n $ nodes. For each node, you either color it in $ 0 $ or $ 1 $ . T ...
- erp——绩效考核系统——数据需求说明书
绩效考核--数据需求说明书 1.引言 1.1编写目的 数据要求说明书详细的提供了系统中各个数据的流向,是设计数据库的关键所在,为以后的编码以及测试提供一份可靠的依据. 1.2 对象 本<数据要求 ...
- smm整合
配置整合 这个里面SpringConfig 就是书写Spring的配置类,其中加载了jdbc配置类和mybatis配置类,还加载了jdbc资源类. package com.itheima.config ...
- 7 HTTP 的报文
目录 1 报文结构 TCP的报文 HTTP协议的报文 2 请求行:request line 3 状态行:status line 4 头部字段 5 常用头字段 基本的头信息 1. Host 字段(必须) ...
- MybatisPlus的一些高级特性
1.MybatisPlus多数据源配合 导入相关依赖 <dependency> <groupId>com.baomidou</groupId> <artifa ...
- AI换脸利器!Roop下载分享
前段时间给大家介绍过换脸界最强的Rope,感兴趣的小伙伴可以戳戳手指 传送门:https://blog.csdn.net/S_eashell?spm=1011.2415.3001.5343 今天要 ...
- hszxoj 矿场搭建 [tarjan]
hszxoj 矿场搭建 题目描述 原题来自:HNOI 2012 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决 ...
- Python——第五章:csv模块
未来我们会使用爬虫获取到一些json文件,例如去英雄联盟官方爬取英雄的数据库 查看代码 {"hero":[{"heroId":"1",&qu ...