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的更多相关文章

  1. CF1327A Sum of Odd Integers 题解

    原题链接 简要题意: 多组数据,问能否把 \(n\) 分为 \(k\) 个 不同的 正奇数之和. 盲猜数学结论题. 只要考虑两个问题: \(n\) 的大小是否足够. \(n\) 的奇偶性是否满足. 对 ...

  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. LeetCode Sum of Two Integers

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

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

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

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

  7. 【LeetCode】Sum of Two Integers

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

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

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

  10. 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. R数据分析:集成学习方法之随机生存森林的原理和做法,实例解析

    很久很久以前给大家写过决策树,非常简单明了的算法.今天给大家写随机(生存)森林,随机森林是集成了很多个决策数的集成模型.像随机森林这样将很多个基本学习器集合起来形成一个更加强大的学习器的这么一种集成思 ...

  2. 一篇学会cron表达式

    1.定义 Cron表达式是一种用于定义定时任务的格式化字符串.它被广泛用于Unix.Linux和类Unix系统中,用于在指定的时间执行预定的任务.Cron表达式由6个字段组成,每个字段通过空格分隔开. ...

  3. 从管易云到MySQL通过接口配置打通数据

    从管易云到MySQL通过接口配置打通数据 数据源平台:管易云 管易云是金蝶旗下专注提供电商企业管理软件服务的子品牌,先后开发了C-ERP.EC-OMS.EC-WMS.E店管家.BBC.B2B.B2C商 ...

  4. 深度解剖Linux权限的概念

    Linux 权限系统是其安全性的基石,它允许系统管理员和用户对文件和目录进行精细的控制.在深度解剖 Linux 权限的概念时,我们需要涵盖以下主题: 1. **文件系统基础** - 文件系统结构:Li ...

  5. ubuntu防火墙ufw基本使用方法

    ubuntu系统基本使用方法 防火墙 # 查看服务器防火墙状态 ufw status # 将防火墙设置为可用状态 ufw enable # 将防火墙设置为关闭状态 ufw disbale # 放行端口 ...

  6. Redis存储商品热度

    项目中有一个需求,就是可以根据商品的热度进行排序 起初想着使用string类型来存储如: sku:hotscore:商品的ID 但是这回有个问题,当商品数量多了那k-v岂不是得炸了,维护起来也非常不方 ...

  7. emoji表情符号备忘单

    记录目的:写文章的时候想用一些小表情或图片,但是上传图片太麻烦还不兼容 emoji表情符号就是很好的选择 国际通用,开箱即用(复制粘贴),兼容性强(理论上能放文本就能放emoji) 博客文档,git文 ...

  8. 《HelloGitHub》第 93 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  9. HTML之CSS Animation 属性常用动画

    引入下面的样式表后 -webkit-animation: tada 1s ease 0.3s infinite both; -webkit-animation: name duration timin ...

  10. IDEA插件(2 高效开发)

    一.高效开发代码插件 ① .TONGYI Lingma(阿里通灵代码AI插件) 提问回答 右键其他功能,只需要登录阿里账号就可以使用 ②.Talk X(AI提示插件,和阿里通灵代码很像的功能) ③.A ...