zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    几个比较好的IT站和开发库官网
    Win7下Qt5.2中使用OpenGL的glu函数库无法使用的解决方案
    QT5.2 Assistant-设置应用程序图标
    linux下文件编码格式转换方法(gb18030/utf-8)
    QT-进制转换计算器
    QT-图标设置
    QT-make: *** No rule to make target
    QT的exe文件打开显示,无法定位程序***输入点于动态链接库****
    QT工程文件上传Github仓库
    Eclipse中文乱码
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12559719.html
Copyright © 2011-2022 走看看