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 -. ...
随机推荐
- AntDesignBlazor示例——新建项目
本示例是AntDesign Blazor的入门示例,在学习的同时分享出来,以供新手参考. 1. 开发环境 VS2022 17.8.2 .NET8 AntDesign 0.16.2 2. 学习目标 创建 ...
- Excel中最牛的Index和match函数介绍
当谈到Excel中最强大的函数时,INDEX和MATCH往往会被提及.它们经常一起使用,可以用来查找和返回数据表中的特定数值或信息.下面是对这两个函数的详细介绍: INDEX 函数: INDEX函数的 ...
- mysql之慢sql配置与分析
mysql的慢查询sql是通过日志记录慢SQL--(俗称慢查询日志)默认的情况下,MySQL数据库不开启慢查询日志(slow query log),需要手动把它打开 开启慢查询日志 SET GLOBA ...
- springboot实现邮箱发送(激活码)功能
第一步:现在邮箱里面开启smtp服务 这里用163邮箱举例,配置一下授权密码,这个要提前记住 第二步:引入依赖 <?xml version="1.0" encoding=&q ...
- MVC:开发模式
1.jsp演变历史 1.早期只有servlet,只能使用response输出标签数据,非常麻烦. 2.后来有了jsp,简化了Servlet的开发,如果过度使用jsp中即写大量的Ja ...
- VS2022 安装 .NET Framework 4.0 和 .NET Framework 4.5 的方法
解决方法 1.下载.NET Framework框架 .NET Framework 4.5.2 .NET Framework 4.5.1 .NET Framework 4.5 .NET Framewor ...
- 牛客刷java记录第5天
第一题,下列代码运行结果是? class X { Y y = new Y(); public X() { System.out.print("X"); } } class Y { ...
- Matrix-writeup
matrix 信息收集 只开放了80端口 换了一个大一点的字典扫到了一个PHP页面 此页面会将输入的内容显示在页面上,抓包之后可以看到他写入到了一个txt文件中 那就可以把一句话写入到一个文件里再去连 ...
- vulntarget-a-wp
vulntarget-a 信息收集 存活扫描,目标开放了445还是win7,考虑一手永恒之蓝 arp-scan -l nmap -A -sT -sV 192.168.130.4 永恒之蓝 用nmap的 ...
- Python汉诺塔递归算法实现
关于用递归实现的原理,请查看我之前的文章: C语言与汉诺塔 C#与汉诺塔 以下为代码: count = 0 def move(pile, src, tmp, dst): global count if ...