23 November 2015

Lightoj 1214- Large Division

Let explain one input. a = -202202202202202202 and b =-101.Make partition of a such that the partition is divisible by b. Look 202 is divisible by 101 and next partition is also 202 which is also divisible by 101. Make the process continue till the end of a. There is one thing to beware which is range of a.   

  

/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size)  for(int i=0 ; i<size ; i++) cin>>array[i]  ;
#define new_line  pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647

int main()
{
    int test ;
    int cnt =1 ;
    sc("%d",&test) ;
    while(test--)
    {
        string str ;
        ll b ;
        cin>>str>>b ;
        b = abs(b) ;
        ll m =0 ;
        ll rem =0 ;
        int t =0 ;
        for(int i=0 ; str[i] ; i++)
        {
            if(str[i]== '-')
                continue ;
            m = m+ (str[i] - '0') ;
            rem = m % b ;
            m = rem * 10 ;
            if(rem==0 && i==str.size()-1)
            {
                t++ ;
                pf("Case %d: divisible\n",cnt++) ;
                break ;
            }
        }
        if(t==0)
            pf("Case %d: not divisible\n",cnt++) ;

    }
    return 0;
}


No comments:

Post a Comment

UVA 10679 - I Love Strings!!