ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1073. Square Country

WA14 pls help
Posted by moshcode 16 Dec 2014 16:01
my code:
#include<iostream>
#include<cmath>
using namespace std;
main()
{
    unsigned int n,temp,nc;
    cin>>n;
    nc=n;
    temp=sqrt(n);
    if(n==0)
    cout<<0;
    else if(temp*temp==n)
    cout<<1;
    else
    {
        unsigned int x=-1,m=0,q=4,t;
        for(unsigned int i=temp;i>=1;i--)
        {
            t=i;
            while(x!=0)
            {
                x=n-t*t;
                n=x;
                t=sqrt(x);
                m++;
            }
        if(m<q)
            q=m;
        if(m==2)
            break;
        x=-1;
        m=0;
        n=nc;
        }
        cout<<q;
    }
}