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;
    }
  • 相关阅读:
    weblogic weak_password 复现
    redis 4-unacc 复现
    Django debug page XSS漏洞(CVE-2017-12794)复现
    (CVE-2016-4437)Apache Shiro <=1.2.4 反序列化漏洞复现
    Apache SSI 远程命令执行漏洞复现
    Apache HTTPD 未知后缀解析漏洞复现
    s2-005复现
    05 跨站请求伪造漏洞CSRF
    安全大面
    JAVA基础学习day03--流程控制语句
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12559719.html
Copyright © 2011-2022 走看看