CodeForces 807B

题意:

给出p,x,y  你可以通过 x+100  x-50两种操作,使得x和p满足下列条件:

   1)x>=y

   2) 

注:(x即下方的s)

p在下方运算输出的25个数中出现过

i := (s div 50) mod 475
repeat 25 times:
    i := (i * 96 + 42) mod 475
    print (26 + i)

 问最少执行多少次+100的操作

 

首先判断,若x>=y,那就先只执行-50的操作

看在x>y的前提下能否只-50就满足要求

否则,再x>y的前提下 先给x+100,判断,再-50,判断

循环直至x满足要求

为什么只减1个50?

若减2个50,那就不用+这个100,若减3个50,在上一次-50就算过了,以此类推

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
const int mod=1e9;
int p;
int check(int x)
{
    int i=(x/50)%475;
    for(int j=0;j<25;j++)
    {
        i=(i*96+42)%475;
        if(26+i==p)
            return 1;
    }
    return 0;
}
int x,y;
int main()
{
    while(~scanf("%d%d%d",&p,&x,&y))
    {
    int x1=x;
    int cnt=0,flag=1;
    while(x1<y)
    {
        x1+=100;
        cnt++;
        flag=0;
    }
    if(flag!=0)
    {
      while(x1>=y)
      {
        x1-=50;
        if(x1<y)
         break;
        if(check(x1))
        {
         printf("%d\n",cnt );
         return 0;
        }
       }
    }
    while(check(x)==0)
    {
      x+=100;
      cnt++;
      if(check(x-50)!=0)
        break;
    }
    printf("%d\n",cnt);
  }
  return 0;
}

题目:

Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.

Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.

Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:

i := (s div 50) mod 475
repeat 25 times:
    i := (i * 96 + 42) mod 475
    print (26 + i)

Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.

As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.

You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.

To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.

You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

Input

The only line contains three integers px and y(26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.

Output

Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.

It's guaranteed that your goal is achievable for any valid input data.

Examples

Input

239 10880 9889

Output

0

Input

26 7258 6123

Output

2

Input

493 8000 8000

Output

24

Input

101 6800 6500

Output

0

Input

329 19913 19900

Output

8

Note

In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places:

475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343

In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.

In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.

In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值