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. 总结(5)--- Numpy和Pandas库常用函数

    二.常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数据进行快速运算的标准 ...

  2. 深入了解Rabbit加密技术:原理、实现与应用

    一.引言 在信息时代,数据安全愈发受到重视,加密技术作为保障信息安全的核心手段,得到了广泛的研究与应用.Rabbit加密技术作为一种新型加密方法,具有较高的安全性和便捷性.本文将对Rabbit加密技术 ...

  3. [ARC158D] Equation

    Problem Statement You are given a positive integer $n$, and a prime number $p$ at least $5$. Find a ...

  4. 7、If分支语句

    1.程序的流程结构 程序的流程控制结构一共有三种: 顺序结构 选择结构 循环结构. 顺序结构: 从上向下 逐行执行 选择结构:条件满足,某些代码才会执行.0-1次 分支语句: if,switch,se ...

  5. JS对后端响应的long类型数据处理精度丢失问题

    1.数据库的数据 2.前端拿到的数据 前端帮我们进行四舍五入了,这并不是我想要的 3.解决办法 把后端响应的数据long类型转成string类型,可以使用Stream流的方式或者for循环的方式,对响 ...

  6. 华企盾DSC客户端右键菜单不显示常见处理方法

    1.检查控制台"客户端不显示右键菜单项" 2.未分发模块权限,若以分配可尝试去掉重新分配模块 3.检查杀毒软件是否杀掉了5097目录的文件(覆盖安装,以上两条没问题,这条比较常见) ...

  7. 华企盾DSC发送白名单提示“解密发送失败”(被中转服务器判定为垃圾邮箱)

    解决方法:用DebugView监控,发现含有550错误,说明中转服务器被判定为垃圾邮箱,换一个中转邮箱或者设置为无中转发送 还有一种可能:邮箱设置了收到邮箱后自动删除 ​ DebugView中显示上图 ...

  8. python 解析网址信息

    python 解析网址信息 本篇文章主要讲述python 中如何解析一个url的信息. 1: requests获取网页信息 #!/usr/bin/python3 # -*- coding: UTF-8 ...

  9. Javascript Ajax总结——XMLHttpRequest对象

    Ajax技术能向服务器异步请求额外的数据,会带来更好的用户体验.Ajax技术核心:XMLHttpRequest对象(简称XHR).XHR为向服务器发送请求和解析服务器响应提供了流畅的接口.1.创建XM ...

  10. WebView中的页面调试方法

    在 iOS 12 中,苹果正式弃用 UIWebView,改成 WKWebView,参考官方声明. 后者在性能.稳定性.功能方面有很大提升,并且与 Safari 具有相同的 JavaScript 引擎( ...