Wednesday, July 26, 2017

UVa problem solution 12465 - The Turanga Leela Problem

problem link:


Discuss: find the difference between two number.then loop as do prime.


try your self  before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,j,cnt,sum,div,h;
    while(cin >>n>>m)
    {
        if(n==0&&m==0)
            break;

        sum=0;
        div=m-n;
        if(div<0)
            div*=-1;
        h=1;
        for(i=2;i<=(int)sqrt(div);i++)
        {
            cnt=0;
            while(div%i==0)
            {
                div/=i;
                cnt++;
            }
            h*=cnt+1;
        }
        if(div!=1)
            h*=2;
        cout <<h<<endl;
    }
    return 0;
}

No comments:

Post a Comment