Tuesday, 8 May 2012

UVa 10787 Modular Equations Solution

#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
#define fill(a,v) memset(a,v,sizeof(a))
#define PB push_back
#define pi acos(-1.0)
#define eps 1e-9


int main()
{
    int amin,amax,bmin,bmax,mmin,mmax,i,j,k,cnt,tc,n;
    cin>>tc;
    for(n=1;n<=tc;n++)
    {

        cnt=0;

        cin>>amin>>amax>>bmin>>bmax>>mmin>>mmax;

        for(i=mmin;i<=mmax;i++)
        {
            if(i%2==0)
                {
                    for(j=bmin;j<=bmax;j++)
                    if(j%(i/2)==0)
                    cnt++;
                }

            else
                {
                    for(j=bmin;j<=bmax;j++)
                    if(j%(i)==0)
                    cnt++;
                }


        }

        cout<<"Case "<<n<<": "<<cnt*((amax-amin)+1)<<endl;
    }
return 0;
}

No comments:

Post a Comment