Codeforces Alyona and Numbers

// Accepted

#include<bits/stdc++.h>

using namespace std;

#define tofast ios_base::sync_with_stdio(false)
#define high 100000010

typedef long long LL;

int main()
{
    tofast;
    LL n, m , i , mul=5 , d, due_col=0 , cnt=0 , quotient;

    while(cin >> n >> m)
    {
        LL i, cnt=0, quotient=0, d=0, due_col=0 , mul=5;

        for(i=1; i<=n; i++)
        {
            if(mul <= i)
            {
                quotient = i / mul;
                mul = (quotient * 5) + 5;
            }

            if(mul > i)
            {
                d = mul - i;

                if(d <= m)
                {
                    cnt+=1;
                    due_col = m - d;
                    cnt+=(due_col / 5); // proti 5 ghor ontor ekta pair ache ze pair er summation 5 dara divisible.
                }
            }

            mul = 5;
        }

        cout << cnt << "\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number