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 1336. Problem of Ben Betsalel

i have problems with 12 test.What is wrong
Posted by Igor 21 Sep 2005 21:06
#include <iostream>
#include <math.h>
using namespace std;

unsigned long long  n,b,c,k,m;
long double f,i;
int main ()
{
   cin >>n;
   b=2;
   if (modf(sqrt((double)n),&i)==0) {cout <<(unsigned long long)sqrt((double)n)<<"\n"; cout <<"1"<<"\n";}
   else
   {
   for ( ;b<=n;b++)
   {
      f=modfl(sqrt((long double)n*(double)(b*b*b)),&i);
      if (f==0) break;
   }
    m=(unsigned long long )sqrt((long double)n*(double)(b*b*b));
   cout <<m<<"\n";
   cout <<b<<"\n";
   }
   return 0;
}
Re: i have problems with 12 test.What is wrong
Posted by PSV 3 Nov 2006 06:27
Are u crazy? :)
Re: i have problems with 12 test.What is wrong
Posted by Denis Koshman 24 Jul 2008 21:08
I had WA12 when I wrote v*v for integer v - it overflowed. Perhaps your long double (equals double for VC++) overflows too. Try putting everything into __int64, no floating point. I use prime factorization for that.