Irrational problem

作者首次参加Codeforces竞赛并使用STL解决了一个涉及数学和组合问题的任务。任务要求计算特定范围内整数的数量,这些整数在经过一系列取余操作后能保持不变的概率至少达到一定标准。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一次做CF,第一次用STL,纪念一下!

 

Codeforces Beta Round #62

 

A. Irrational problem

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya was given this problem for homework:

You are given function (here represents the operation of taking the remainder). His task is to count the number of integers x in range [a;b] with property f(x) = x.

It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.

Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that f(x) = x is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number x if there exist at least 7 permutations of numbers p1, p2, p3, p4, for which f(x) = x.

Input

First line of the input will contain 6 integers, separated by spaces: p1, p2, p3, p4, a, b (1 ≤ p1, p2, p3, p4 ≤ 1000, 0 ≤ a ≤ b ≤ 31415).

It is guaranteed that numbers p1, p2, p3, p4 will be pairwise distinct.

Output

Output the number of integers in the given range that have the given property.

Sample test(s)
Input
2 7 1 8 2 8
Output
0
Input
20 30 40 50 0 100
Output
20
Input
31 41 59 26 17 43
Output
9

比着刘汝佳白皮书上的下一个排列写的,继续努力吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值