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. 删除当前文件夹不是.vue文件,电脑命令符

    ::-----------------------------------------@echo offsetlocal EnableDelayedExpansionset _thisFilePath ...

  2. 发现AI自我意识:不期而遇的局部技术奇点

    Q*的启示 之前的文章里提到过,人工智能思维能力创造的必不可少的条件是状态空间的搜索.今天的大新闻里,我们都看到了Q*的确使用了搜索算法.所以今天我会稍微谈一下这个话题. 主要思想就是人工智能的进一步 ...

  3. Android 输入系统介绍

    目录 一.目的 二.环境 三.相关概念 3.1 输入设备 3.2 UEVENT机制 3.3 JNI 3.4 EPOLL机制 3.5 INotify 四.详细设计 4.1 结构图 4.2 代码结构 4. ...

  4. .NET周刊【11月第4期 2023-11-26】

    国内文章 万字长文:从 C# 入门学会 RabbitMQ 消息队列编程 https://www.cnblogs.com/whuanle/p/17837034.html 如题,详细的介绍RabbitMQ ...

  5. python的列表、元组

    列表(list):是Python中最常用的数据类型之一,字符串里面包含元素的是 一个个的字符,并且字符串是不可能更改的,然而列表不一样,他的每个元素都 可以是任何python类型,而且是可以被更改的 ...

  6. BASE和最终一致性

    四种性质: 基本可用性,软状态,强一致性,弱一致性 更据更新数据后各进程访问到数据的时间和方式不同: 如何实现各种类型的一致性: 对于HBase数据库来讲:

  7. MybatisPlus查询时过滤不需要的字段~

    解释一下:乍一看标题可能有点懵~,其实就是想查询的时候过滤掉某些字段 例如: select name,email,password from user; --改为-> select name,e ...

  8. docker 设计及源码分析

    1.dockerd 是一个长期运行的守护进程(docker daemon).负责管理 docker 容器的生命周期.镜像和存储等.实际还是通过grpc 的协议调用 containerd 的 api 接 ...

  9. 第三方登陆--QQ登陆--前后端分离版本

    从零玩转第三方QQ登陆 下面有源码 第三方GITEE登陆 https://www.cnblogs.com/Yangbuyi/p/yangbuyi.html 在真正开始对接之前,我们先来聊一聊后台的方案 ...

  10. 谁再说学不会 MySQL 数据库,就把这个给他扔过去!

    大家好,我是民工哥. 又是新的一年奋斗路的开启,相信有不少人农历新年之后,肯定会有所变动(跳槽加薪少不了).所以,我把往期推送过的MySQL技术文章做了一个相关的整理,基础不好的可以从最基础的学习一遍 ...