Thursday, July 30, 2015

1140 - How Many Zeroes?

#include<bits/stdc++.h>
using namespace std;
 
long long calculate(long long a)
{
    long long len,st[100],l=1,n=a;
 
    while(1)
    {
        if(a < 10)
        {
            st[l++] = a;
            break;
        }
        st[l++] = a%10;
        a /= 10;
    }
    long long res = 0;
    for(int i=1; i<l; i++)
    {
        if(i==1 || st[i] != 0)
        {
            res += pow(10,i-1) * floor(n/pow(10,i));
        }
 
        else
        {
            res += (pow(10,i-1) * (floor(n/pow(10,i))-1))+n+1-pow(10,i)*floor(n/pow(10.00,i));
        }
    }
    return res;
}
 
int main()
{
    long long T,i,k,m,n,l,result1,result2,c=1;
    cin >> T;
    while(T--)
    {
        cin >> m >> n;
        result1 = calculate(m-1);
        result2 = calculate(n);
        cout << "Case " << c++ << ": " << result2-result1 << endl;
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...