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

Re:Algorithm from F. J. Gruenberger, "What Should We Compute?", RAND

Posted by 070101070260 at 2012-10-18 11:38:44 on Problem 3795
In Reply To:Algorithm from F. J. Gruenberger, "What Should We Compute?", RAND Posted by:070101070260 at 2012-10-18 11:36:52
package Solution;
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Solution {
	public static void main(String args[]) throws Exception
	{
		new A().main();
	}
}
class A
{
	Scanner cin=new Scanner(new BufferedInputStream(System.in));
	PrintStream cout=System.out;
	BigInteger a,b,c,d,mod=new BigInteger("100000000000000000000");
	BigInteger res,one=BigInteger.ONE;
	BigInteger p,delta=BigInteger.ONE,five=BigInteger.valueOf(5);
	BigInteger four=BigInteger.valueOf(4);
	BigInteger two=BigInteger.valueOf(2);
	boolean check(BigInteger n,int r)
	{
		for(;r>0;r--)
		{
			int d=n.mod(BigInteger.TEN).intValue();
			n=n.divide(BigInteger.TEN);
			if(d<1||d>2) return false;
		}
		return true;
	}
	void go(int len)throws Exception
	{
		//System.out.println(" "+len);
		while(true)
		{
			res=two.modPow(p, mod);
		//	System.out.println(delta);
			if(check(res,len))
			{
				System.out.println(p+"ll,");
				break;
			}
			p=p.add(delta);
		}
	}
	void main()throws Exception
	{
		p=BigInteger.ONE;
		int i,j,k;
		delta=four;
		for(i=2;i<=20;i++)
		{
			go(i);
			
			delta=delta.multiply(five);
		}
	}
}

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