Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

27237237 --- no solution

Posted by frkstyc at 2005-07-05 18:28:32 on Problem 2427
In Reply To:谁给一组数据 Posted by:lookus at 2005-07-05 17:51:53
> 代码是很久以前写的(现在看不懂了),但没过,改了一下,测了很多数据好像还可以,就是WA
> 
> import java.util.*;
> import java.math.*;
> 
> public class Main
> {
>     public static void main(String args[])
>     {
>         final BigInteger inf = BigInteger.TEN.pow(1000);
>         BigInteger g[], b[];
>         int d, a[], p[], q[], i, j, a02;
>         double d2;
>         Scanner cin = new Scanner(System.in);
>         try
>         {
>             a = new int[50000];
>             p = new int[50000];
>             q = new int[50000];
>             p[0] = 0;
>             q[0] = 1;
>             for (;;)
>             {
>                 d = cin.nextInt();
>                 d2 = Math.sqrt(d);
>                 int dd = (int) (d2+0.000001);
>                 if (dd * dd == d)
>                 {
>                     System.out.println("No solution!");
>                     continue;
>                 }
>                 a02 = (int) ((p[0] + d2) / q[0]) * 2;
>                 g = new BigInteger[50000];
>                 b = new BigInteger[50000];
>                 g[0] = BigInteger.valueOf(0);
>                 g[1] = BigInteger.valueOf(1);
>                 b[0] = BigInteger.valueOf(1);
>                 b[1] = BigInteger.valueOf(0);
>                 for (i = 0;; ++i)
>                 {
>                     a[i] = (int) ((p[i] + d2) / q[i]);
>                     if (a[i] == a02)
>                         break;
>                     p[i + 1] = a[i] * q[i] - p[i];
>                     q[i + 1] = (d - p[i + 1] * p[i + 1]) / q[i];
>                     g[i + 2] = g[i + 1].multiply(BigInteger.valueOf(a[i])).add(
>                             g[i]);
>                     b[i + 2] = b[i + 1].multiply(BigInteger.valueOf(a[i])).add(
>                             b[i]);
>                 }
>                 if ((i & 1) == 1)
>                 {
>                     int ii = 2 * (i+1);
>                     for (; i < ii; ++i)
>                     {
>                         a[i] = (int) ((p[i] + d2) / q[i]);
>                         p[i + 1] = a[i] * q[i] - p[i];
>                         g[i + 2] = g[i + 1].multiply(BigInteger.valueOf(a[i]))
>                                 .add(g[i]);
>                         b[i + 2] = b[i + 1].multiply(BigInteger.valueOf(a[i]))
>                                 .add(b[i]);
>                     }
>                     if(inf.compareTo(g[i-1])>0 && inf.compareTo(b[i-1])>0)
>                         System.out.println(g[i - 1].toString() + " "
>                                 + b[i - 1].toString());
>                     else
>                         System.out.println("No solution!");
>                 }
>                 else
>                     if(inf.compareTo(g[i+1])>0 && inf.compareTo(b[i+1])>0)
>                         System.out.println(g[i + 1].toString() + " "
>                                 + b[i + 1].toString());
>                     else
>                         System.out.println("No solution!");
>             }
>         } catch (Exception e)
>         {
>         }
>     }
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator