Educational Codeforces Round 84 (Rated for Div. 2), problem: (A) Sum of Odd Integers

Posted wyh447154317

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 84 (Rated for Div. 2), problem: (A) Sum of Odd Integers相关的知识,希望对你有一定的参考价值。

A.

被卡了好久,样例的第一感觉n%k==0则YES

后来写式子,交了发n>=k*k 虽然写的时候也注意到了n-k必须是偶数(k个奇数和的奇偶性与k相同,故n与k奇偶性相同)

最后才想到,可以构造 前k-1个数为1~k-1 剩下的即为第k个数

 

技术图片

 

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//const int N=1e4+5;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        ll n,k;
        cin>>n>>k;
        if(n>=k*k&&n%2==k%2)cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
    }
    return 0;
}

 

比赛时交的

#include<bits/stdc++.h>
#define ll long long
using namespace std;
//const int N=1e4+5;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        ll n,k;
        cin>>n>>k;
        if((n-(k-1)*(k-1))%2&&(n-(k-1)*(k-1))>=2*k-1)cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
    }
    return 0;
}

B

 

以上是关于Educational Codeforces Round 84 (Rated for Div. 2), problem: (A) Sum of Odd Integers的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27