CSDN同步

原题链接

简要题意:

多组数据,问能否把 \(n\) 分为 \(k\) 个 不同的 正奇数之和。

盲猜数学结论题。

只要考虑两个问题:

  1. \(n\) 的大小是否足够。

  2. \(n\) 的奇偶性是否满足。

对于第 \(1\) 条,最小的 \(k\) 个 不同的 正奇数之和为 \(k^2\).(这都不知道,建议重学小学数学)

所以,\(n \geq k^2\) 才可能有解。

对于第 \(2\) 条,因为 \(k\) 个正奇数与 \(k\) 的奇偶性相同,所以必须满足:

\[n \equiv k \pmod 2
\]

这两条同时满足即有解,否则无解。

为什么呢?

考虑一种拆分:

\[1 + 3 + 5 + ... + (2k-3) + p = n
\]

即前 \(k-1\) 个正奇数加上另一个奇数。

如果 \(n\) 同时满足上两条,则显然存在这样的拆分,且 \(p \geq 2 \times k - 1\),也不存在重复。

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std; typedef long long ll; inline ll read(){char ch=getchar();int f=1;while(ch<'0' || ch>'9') {if(ch=='-') f=-f; ch=getchar();}
ll x=0;while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;} int main(){
ll T=read(),n,k; while(T--) {
n=read(),k=read();
if(n<k*k || (n-k)&1) puts("NO");
else puts("YES");
} //别忘了,k*k会爆int,开上 long long
return 0;
}

CF1327A Sum of Odd Integers 题解的更多相关文章

  1. LeetCode Sum of Two Integers

    原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...

  2. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  3. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  4. LeetCode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. leetcode371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  6. 【LeetCode】Sum of Two Integers

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  7. 每天一道LeetCode--371. Sum of Two Integers

    alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...

  8. 371. Sum of Two Integers -- Avota

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  9. Leetcode 371: Sum of Two Integers(使用位运算实现)

    题目是:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

随机推荐

  1. linux Init分析(原创)

    1.uboot的目标就是启动内核kernel: 2.kernel的目的就是启动应用程序,而第一个应用程序即是Init,构建根文件系统. 从uboot初始化配置后,引导内核的启动,启动函数为:start ...

  2. scrapy爬虫-代理IP中间件

    class ProxyDownloaderMiddleware(object): # Not all methods need to be defined. If a method is not de ...

  3. 【2020Python修炼记3】初识Python,你需要知道哪些(一)

    一.编程语言简介 机器语言 计算机能直接理解的就是二进制指令,所以机器语言就是直接用二进制编程,这意味着机器语言是直接操作硬件的,因此机器语言属于低级语言, 此处的低级指的是底层.贴近计算机硬件(贴近 ...

  4. Java面试必问之Hashmap底层实现原理(JDK1.7)

    1. 前言 Hashmap可以说是Java面试必问的,一般的面试题会问: Hashmap有哪些特性? Hashmap底层实现原理(get\put\resize) Hashmap怎么解决hash冲突? ...

  5. 基于均值坐标(Mean-Value Coordinates)的图像融合算法的具体实现

    目录 1. 概述 2. 实现 2.1. 准备 2.2. 核心 2.2.1. 均值坐标(Mean-Value Coordinates) 2.2.2. ROI边界栅格化 2.2.3. 核心实现 2.2.4 ...

  6. 基于vue开发的在线付费课程应用

    最近在弄一个付费课程的应用,主要有微信登录,支付和自定义分享,在开发过程中遇到的坑,这里做一下记录 文章主要有以下几点 使用库简介 微信登录解决 微信支付解决 微信自定义分享解决 页面前进后退数据状态 ...

  7. HTML5 Canvas(基础知识)

    最近笔者在学习HTML5的新元素<canvas>,会分享一些基础知识以及小例子,最终使用<canvas>实现一个绘制简单图表(条形图.线图或者饼图)的js库,会更新一到两篇文章 ...

  8. 一步步去阅读koa源码,整体架构分析

    阅读好的框架的源码有很多好处,从大神的视角去理解整个框架的设计思想.大到架构设计,小到可取的命名风格,还有设计模式.实现某类功能使用到的数据结构和算法等等. 使用koa 其实某个框架阅读源码的时候,首 ...

  9. 我折腾的shell笔记

    目录 Mac一些常用的快捷键记录 iTerm2或者命令行相关 Mac桌面上或者某目录下操作 一些实用脚本示例 代码无提示或者其他抽风症状,清除Xcode缓存 查看当前网络ip地址 日常提交推送git代 ...

  10. 什么是SSH与SSH客户端

    1.什么是SSH? SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议.SS ...