Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Team Proof
- Java template
- */
- import java.io.*;
- import java.util.*;
- import java.math.*;
- public class Main
- {
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- StringTokenizer tokenizer=null;
- public static void main(String[] args) throws IOException
- {
- new Main().execute();
- }
- void debug(Object...os)
- {
- System.out.println(Arrays.deepToString(os));
- }
- int ni() throws IOException
- {
- return Integer.parseInt(ns());
- }
- long nl() throws IOException
- {
- return Long.parseLong(ns());
- }
- double nd() throws IOException
- {
- return Double.parseDouble(ns());
- }
- String ns() throws IOException
- {
- while (tokenizer == null || !tokenizer.hasMoreTokens())
- tokenizer = new StringTokenizer(br.readLine());
- return tokenizer.nextToken();
- }
- String nline() throws IOException
- {
- tokenizer=null;
- return br.readLine();
- }
- //Main Code starts Here
- int totalCases, testNum;
- BigInteger g,x,y;
- void extgcd(BigInteger a,BigInteger b)
- {
- if(b.equals(BigInteger.ZERO))
- {
- g=a;
- x=BigInteger.ONE;
- y=BigInteger.ZERO;
- }
- else
- {
- BigInteger div = a.divide(b);
- extgcd(b,a.subtract(b.multiply(div)));
- BigInteger temp=x;
- x=y;
- y=temp.subtract((div).multiply(y));
- }
- }
- BigInteger ans1,ans2;
- void CRT(BigInteger m1,BigInteger m2)
- {
- extgcd(m1,m2);
- ans1=x.multiply(m1);
- if(ans1.compareTo(BigInteger.ZERO) < 0)
- ans1=ans1.add(pow10);
- ans2=y.multiply(m2);
- if(ans2.compareTo(BigInteger.ZERO) < 0)
- ans2=ans2.add(pow10);
- }
- void execute() throws IOException
- {
- preprocess();
- totalCases = ni();
- for(testNum = 1; testNum <= totalCases; testNum++)
- {
- if(!input())
- break;
- solve();
- }
- }
- int N;
- BigInteger two,five,ten;
- BigInteger pow2,pow5,pow10;
- String[] ans=new String[505];
- void preprocess()
- {
- two=BigInteger.valueOf(2);
- five=BigInteger.valueOf(5);
- ten=BigInteger.valueOf(10);
- pow2=two;
- pow5=five;
- pow10=ten;
- for(int i=2;i<=500;i++)
- {
- pow2=pow2.multiply(two);
- pow5=pow5.multiply(five);
- pow10=pow10.multiply(ten);
- CRT(pow2,pow5);
- if(ans1.compareTo(ans2) < 0)
- ans[i] = ans1.toString() + " " + ans2.toString();
- else
- ans[i] = ans2.toString() + " " + ans1.toString();
- }
- }
- void solve()
- {
- if(N==1)
- {
- System.out.println("Case #"+testNum+": 0 1 5 6");
- return;
- }
- System.out.print("Case #"+testNum+": ");
- System.out.println(ans[N]);
- }
- boolean input() throws IOException
- {
- N=ni();
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement