Time Limit: | Memory Limit: | 64bit IO Format: |
Description
Little Petya was given this problem for homework:
You are given function
It is a pity that Petya forgot the order in which the remaindersshould be taken and wrote down only 4 numbers. Each of 24 possibleorders of taking the remainder has equal probability of beingchosen. For example, if Petya has numbers 1, 2, 3, 4 then he cantake remainders in that order or first take remainder modulo 4,then modulo 2, 3, 1. There also are 22 other permutations of thesenumbers that represent orders in which remainder can be taken. Inthis problem 4 numbers wrote down by Petya will be pairwisedistinct.
Now it is impossible for Petya to complete the task given byteacher but just for fun he decided to find the number ofintegers
Input
First line of the input will contain 6 integers, separated byspaces:
It is guaranteed that numbers
Output
Output the number of integers in the given range that have thegiven property.
Sample Input
2 7 1 8 2 8
0
20 30 40 50 0 100
20
31 41 59 26 17 43
9
#include<iostream>
using namespace std;
int main()
{
int a,b,p1,p2,p3,p4,count;
while(cin>>p1>>p2>>p3>>p4>>a>>b)
{
count=0;
for(int i=a;i<=b;i++)
if((((i%p1)%p2)%p3)%p4==i)
count++;
cout<<count<<endl;
}
return 0;
}