数学题(1)

I.Sum of One-sequence
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 168(45 users)Total Accepted: 38(35 users)Special Judge: No
Description

We say that a sequence of integers is a onesequence if the difference between any two consecutive numbers in this sequence is -1 or 1 and its first element is 0. More precisely: a1a2, ..., ais a one-sequence if:

· for any (1 ≤ n): |aak+1|=1,

· a1=0.

You are given n and s — sum of all elements in a. Construct a one-sequence with the given parameters.

Input

The first line contains a pair of integers n and s (1≤n ≤10000, |s| ≤ 50000000).

Output

Print “Yes" if required sequence exist ... or "No" if it doesn't exist.

Sample Input

8 4

Sample Output

Yes

好吧这道题目是田大神交我的,是个动脑子的题目,果然我脑子不好使。。。QAQ

题意:给你一个长度为n的数组,a1 =0,|ak-a(k+1)|=1....然后问你是否可以产生和为s的数

分析:这真是赤裸裸的靠数学智商啊。。。。哎。。。。

n = 1     

n = 2    1   -1

n = 3  2   0   -2

n = 4         3        1          -1        -3

       。。。。。。。

找规律吧,奇数+奇数=偶数,那么我们找由多少行是奇数行。比如现在n=4,总共由2个奇数行吧,这两行随意取个数相加答案就是偶数,因为其余行都是偶数,所以我们找出有多少个奇数行就行,如果奇数行行数是奇数那么答案一定是个奇数,否则是偶数

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int n,s;
    while(cin>>n>>s)
    {
            s= abs(s);
            int   sum = n*(n-1)/2;
            if(abs(sum) >= s  &&  s%2 == (n/2)%2)
             cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值