Codeforces Round #461 (Div. 2)题解ABC

A. Cloning Toys
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Imp likes his plush toy a lot.

Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.

Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.

Input

The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).

Output

Print "Yes", if the desired configuration is possible, and "No" otherwise.

You can print each letter in arbitrary case (upper or lower).

Examples
input
6 3
output
Yes
input
4 2
output
No
input
1000 1001
output
Yes
Note

In the first example, Imp has to apply the machine twice to original toys and then twice to copies.

题意:

只有一个原始的玩具,经过各种操作能否拥有x个原始玩具和y个复制玩具,投一个原始的,得到一个原始一个复制,投一个复制得到两个复制。

找规律,x=y-1+2n,x>=0,y>=0,n>=0=>x-y+1>=0,y-1>=0,注意细节

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if((y-1)>=0&&(x-y+1)>=0&&((y-1>0&&(x-y+1)%2==0)||x==0))
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}


B. Magic Forest
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Imp is in a magic forest, where xorangles grow (wut?)

A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest. 

Formally, for a given integer n you have to find the number of such triples (a, b, c), that:

  • 1 ≤ a ≤ b ≤ c ≤ n
  • , where  denotes the bitwise xor of integers x and y
  • (a, b, c) form a non-degenerate (with strictly positive area) triangle. 
Input

The only line contains a single integer n (1 ≤ n ≤ 2500).

Output

Print the number of xorangles of order n.

Examples
input
6
output
1
input
10
output
2
Note

The only xorangle in the first sample is (3, 5, 6).

题意

给定一个正整数nn ,求满足如下条件的三元组(a,b,c)(a,b,c) 的个数:

  • 1≤a≤b≤c≤n1abcn
  • a xor b xor c=0a xor b xor c=0
  • 存在一个边长分别为a,b,ca,b,c 的三角形。
异或的性质: 当c=a^b,那么a^b^c==0。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,sum=0,c;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
        {
            c=i^j;
            if(c<=n&&c>=j&&(i+j)>c)//判断c>=b>=a和a,b,c构成三角形
            {
               sum++;
            }
        }
    printf("%d\n",sum);
    return 0;
}
C. Cave Painting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Imp is watching a documentary about cave painting.

Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.

Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 

  • 1 ≤ i < j ≤ k
  • , where  is the remainder of division x by y
Input

The only line contains two integers nk (1 ≤ n, k ≤ 1018).

Output

Print "Yes", if all the remainders are distinct, and "No" otherwise.

You can print each letter in arbitrary case (lower or upper).

Examples
input
4 4
output
No
input
5 3
output
Yes
Note

In the first sample remainders modulo 1 and 4 coincide.

题意:

给两个数,n和m,然后用n对1到m取余数,要求所有余数都不相同。

这道题,当天做的时候记得过了,然后一觉醒来WA在了第71个点,Emmm,想着暴力出奇迹,然并卵,还是应该多思考用更好的方法。

根据推理,需满足n%i==i-1。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    long long i,j,k,n;
    while(~scanf("%lld%lld",&n,&k))
    {
        int f = 0;
        for(i = 1;i<=k;i++)
        {
            if(n%i!=i-1)
            {
                f = 1;
                break;
            }
        }
        if(f) printf("No\n");
        else printf("Yes\n");		
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值