UVA 11428 Cubes Solution

Solve in C:

#include<stdio.h>
#include<math.h>
int main()
{

    long long int i,j,m,n,a,k,count=0;
    while(scanf("%lld",&n)!=EOF)
    {
        if(n==0)
            break;
        count=0;
        a=sqrt(n);
        {
            for(i=1; i<=a; i++)
            {
                for(j=0; j<=i; j++)
                {

                    if(((i*i*i)-(j*j*j))==n)
                    {
                        count++;
                        m=i,k=j;
                        break;
                    }
                }
                if(count==1)
                    break;
            }
            if(count==1)
                printf("%lld %lld\n",m,k);
            else
                printf("No solution\n");

        }

    }


}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.