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 1593. Square Country. Version 2

WA 32. Why?
Posted by Yagudin Ruslan 5 May 2013 20:06
#include <queue>
#include <iostream>
#include <set>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <string>
#include <sstream>
using namespace std;
bool k(long double x)
{
    long double t=floor((sqrt(x)));
    if (t*t==x)
    {
        return true;
    }
    else
        return false;
}
int main()
{
    long double n;

    scanf("%lf",&n);
    long long c=n;
    if(k(n))
    {
        cout<<1;
        return 0;
    }

    for(long int i=1;i<=sqrt(n)/2+2100000;i++)
    {
        long double q=n-i*i;
        if(k(q))
        {
            printf("%d",2);
            return 0;
        }
    }
    for(long int i=sqrt(n);i>=sqrt(n)-2100000;i--)
    {
        long double q=n-i*i;
        if(k(q))
        {
            printf("%d",2);
            return 0;
        }
    }
    long long q = (long long)n;
    for ( int i = 0; i <20; i ++)
    {
        long long d = 1;
        for ( int j = 0; j < i;j++)
        {
            d*=4;
            if ( q > n)
            break;
        }
        if ( d > q)
            break;
        if( (long long)q % d==0)
        {
            long long temp = q/d - 7;
            if ( temp %8==0)
            {
                printf("%d",4);
                return 0;
            }

        }
    }

    printf("%d",3);
    return 0;
}
Re: WA 32. Why?
Posted by ER 10 Jun 2014 11:43
I think you want i<=sqrt(n/2) not  i<=sqrt(n)/2.