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 IntegersXIn range [A;B]
PropertyF(X) Bytes = bytesX.
It is a pity that Petya forgot the order in which the remainders shoshould 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
Property that probability thatF(X) Bytes = bytesXIs not less than 31.4159265352718281828459045%.
In other words, Petya will pick up the numberXIf there exist at least 7 Permutations
Of numbersP1, bytes,P2, bytes,P3, bytes,P4,
For whichF(X) Bytes = bytesX.
Input
First line of the input will contain 6 integers, separated by spaces:P1, bytes,P2, bytes,P3, bytes,P4, middle,A, Bytes,B(1 digit ≤ DigitP1, bytes,P2, bytes,P3, bytes,P4 records ≤ limit 1000, limit 0 records ≤ limitALimit ≤ limitBLimit ≤ limit 31415 ).
It is guaranteed that numbersP1, bytes,P2, bytes,P3, bytes,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
Problem solving Description: this is actually the case where f (x) = x mod P1 mod P2 mod P3 mod P4 = X, but P1, P2, P3, P4 do not know the order, only seven of the 24 combinations are required. When X is smaller than P1, P2, P3, and P4, it must satisfy the meaning of the question. However, when X is larger than any other one, the calculation result is certainly not equal to X. In fact, these seven questions are just a blind man and have no significance.
#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);}