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. swiper轮播图出现疯狂抖动(小程序)

    swiper轮播图息屏一段时间或快速滑动切换时出现疯狂抖动 以前做小程序项目的时候,没专门测试人员,都是开发者自测,可能我的手机性能比较不错(哈哈)或时机不对,总之没发掘到这个bug:近期做项目,测试 ...

  2. 一个基于.NET Core开源、跨平台的仓储管理系统

    前言 今天给大家推荐一个基于.NET Core开源.跨平台的仓储管理系统,数据库支持MSSQL/MySQL:ZEQP.WMS. 仓储管理系统介绍 仓储管理系统(Warehouse Management ...

  3. 如何使用JavaScript 将数据网格绑定到 GraphQL 服务

    前言 作为一名前端开发人员,GraphQL对于我们来说是令人难以置信的好用.它可以用来简化数据访问,这让我们的工作变得更加容易. 什么是 GraphQL?它是一个抽象层,位于任意数量的数据源之上,并为 ...

  4. 海量电商数据与用友YS系统数据对接案例

    案例背景 客户是历史比较悠久的企业.企业内部用的系统多达十几套,专门成立信息化公司进行数字化转型,第一期需求系统旺店通的ERP以及旺店通的WMS并且启用京东的沧海外仓. 在选型ERP用友ERP和金蝶E ...

  5. Python 中的单下划线和双下划线

    哈喽大家好,我是咸鱼 当我们在学习 Python 的时候,可能会经常遇到单下划线 _ 和双下划线 __ 这两种命名方式 单下划线 _ 和双下划线 __ 不仅仅是只是一种简单的命名习惯,它们在 Pyth ...

  6. typora写作

    平时写博客,一般采用typora,但是字体颜色和上传到博客园的图片大小和居中问题,总是很糟糕,偶然发现输入法里面还有自定义的短语,能够解决这个问题. <p><img src=&quo ...

  7. 路径规划算法 - 求解最短路径 - Dijkstra(迪杰斯特拉)算法

    Dijkstra(迪杰斯特拉)算法的思想是广度优先搜索(BFS) 贪心策略. 是从一个顶点到其余各顶点的最短路径算法,节点边是不各自不同的权重,但都必须是正数 如果是负数,则需要 Bellman-Fo ...

  8. 自上而下的LL(1)语法分析法

    LL(1)文法:从文法的开始符,向下推导,推出句子. 对文法G的句子进行确定的自顶向下语法分析的充分必要条件是,G的任意两个具有相同左部的 产生式A->α|β 满足下列条件: (1)如果α.β均 ...

  9. Angular 集成 Material UI 后组件显示不正常 踩坑日记

    在使用了 npm 下载 Material 后, 项目不能正常使用 Material 组件, 随后又使用官方命令使用 Material 组件, 仍然不能正常使用 Material 组件. npm 命令 ...

  10. Mybatis源码3 CachingExecutor, 二级缓存,缓存的实现

    Mybatis CachingExecutor, 二级缓存,缓存的实现 一丶二级缓存概述 上一章节,我们知道mybaits在构造SqlSession的时候,需要让SqlSession持有一个执行器,如 ...