Educational Codeforces Round 84 (Rated for Div. 2) A. Sum of Odd Integers(思维题)

You are given two integers nn and kk. Your task is to find if nn can be represented as a sum of kk distinct positive odd (not divisible by 22) integers or not.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t1051≤t≤105) — the number of test cases.

The next tt lines describe test cases. The only line of the test case contains two integers nn and kk (1n,k1071≤n,k≤107).

Output

For each test case, print the answer — "YES" (without quotes) if nn can be represented as a sum of kk distinct positive odd (not divisible by 22) integers and "NO" otherwise.

Example
Input
Copy
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
Copy
YES
YES
NO
YES
YES
NO
挺好一道思维水题,一开始没看到distinct直接WA到怀疑人生...
举个例子就能明白,比如k=4,组合出来的最小值为1+3+5+7=16,之后可以对某些数+2使得能够组合出例如3+3+5+7=18,所以k=4的话能组合出16 18 20 22......全为偶数,而如果k=3能组合出9 11 13......全为奇数,所以首先判断n和k的奇偶性,如果相同的话看看是否大于这个k能组合出的最小数即可。最小值可以用等差数列算,记得得开long long。
复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n,k;
        cin>>n>>k;
        long long mmin=(1+2*k-1)*k/2;
        if(k%2==0)
        {
            if(n>=mmin&&n%2==0)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else
        {
            if(n>=mmin&&n%2!=0)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
    }
    return 0;
}
复制代码

 

posted @   脂环  阅读(194)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩