1327A Sum of Odd Integers(思维)

1327A Sum of Odd Integers(思维)

题面

题意:有 T T T 个询问,每个询问给出两个整数 n n n k k k,问 n n n 是否能够用 k ​ k​ k 个不同正奇数之和。

范围 1 ≤ T ≤ 1 0 5   ,   1 ≤ n , k ≤ 1 0 7 ​ 1 \le T \le 10^5~,~1 \le n, k \le 10^7​ 1T105 , 1n,k107

分析:已知 k k k 个不同正奇数可以表示的最小数字是 1 + 3 + 5 + . . . + 2 k − 1 = k 2 1+3+5+...+2k-1 = k^2 1+3+5+...+2k1=k2, 之后可以改变其中任意一个数字就可以得到 k 2 + 2 , k 2 + 4 , . . . k 2 + 2 m k^2+2,k^2+4,...k^2+2m k2+2,k2+4,...k2+2m,因此我们只需要判断 n ≥ k 2 n \ge k^2 nk2 n n n k ​ k​ k 的奇偶性相同即可。

Code

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

// const int MAXN =
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double PI = acos(-1.0);

int n;

inline int read()
{
    int s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

signed main()
{
    int T = read();
    while (T--)
    {
        int a, b;
        cin >> a >> b;
        if (a >= b * b && a % 2 == b % 2)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}

【END】感谢观看

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值