现在的位置: 首页 > 综合 > 正文

A. Irrational problem

2012年12月22日 ⁄ 综合 ⁄ 共 1833字 ⁄ 字号 评论关闭
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

解题说明:此题其实就是求f(x)=x mod p1 mod p2 mod p3 mod p4=x的情况,不过p1,p2,p3,p4顺序不知,只需要满足24种组合中的7个而已。当x比p1,p2,p3,p4都小的时候,肯定满足题意,但是当x比其中任意一个都大时,无论如何排列,运算的结果肯定都不会等于x。所以其实这题7个只是幌子而已,没有任何意义。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include<set>
#include <algorithm>
using namespace std;

int main()
{
	int p1,p2,p3,p4,a,b;
	int ret=0,i;
	scanf("%d %d %d %d %d %d",&p1,&p2,&p3,&p4,&a,&b);
	for(i=a;i<=b;i++)
	{
		if(i<p1 && i<p2 && i<p3 && i<p4)
		{
			ret++;
		}
	}
	printf("%d\n",ret);
}

	

抱歉!评论已关闭.