M
mukesh tiwari
Hello all
I am trying to solve a problem on
http://uva.onlinejudge.org/index.ph...d=8&category=12&page=show_problem&problem=964
but i am consistently getting runtime error. I asked about this on
forum of respective site but no luck so i am asking here.
Thank you
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package uvaproblem_10023;
import java.io.*;
import java.math.BigInteger;
/**
*
* @author user
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
BufferedReader stdin= new BufferedReader(new
InputStreamReader(System.in));
String s_1=stdin.readLine();
// stdin.readLine();//for blank line
int n=Integer.parseInt(s_1);
boolean f=false;
for(int i=0;i<n;i++)
{
if(f)System.out.println();
f=true;
String s_2=stdin.readLine();
BigInteger x=new BigInteger(s_2);
BigInteger lo=BigInteger.ZERO,hi=x,mid;
while(lo.compareTo(hi)<0)
{
mid=(lo.add(hi)).divide(new BigInteger("2"));
BigInteger res=mid.pow(2);
if(res.compareTo(x)<0) lo=mid.add(new BigInteger("1"));
else hi=mid;
}
mid=(lo.add(hi)).divide(new BigInteger("2"));
//System.out.println(lo+" "+mid+" "+hi+" "+mid.pow(2));
System.out.println(mid);
}
}catch (NumberFormatException e){}
catch(IOException e){}
}
}
I am trying to solve a problem on
http://uva.onlinejudge.org/index.ph...d=8&category=12&page=show_problem&problem=964
but i am consistently getting runtime error. I asked about this on
forum of respective site but no luck so i am asking here.
Thank you
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package uvaproblem_10023;
import java.io.*;
import java.math.BigInteger;
/**
*
* @author user
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
BufferedReader stdin= new BufferedReader(new
InputStreamReader(System.in));
String s_1=stdin.readLine();
// stdin.readLine();//for blank line
int n=Integer.parseInt(s_1);
boolean f=false;
for(int i=0;i<n;i++)
{
if(f)System.out.println();
f=true;
String s_2=stdin.readLine();
BigInteger x=new BigInteger(s_2);
BigInteger lo=BigInteger.ZERO,hi=x,mid;
while(lo.compareTo(hi)<0)
{
mid=(lo.add(hi)).divide(new BigInteger("2"));
BigInteger res=mid.pow(2);
if(res.compareTo(x)<0) lo=mid.add(new BigInteger("1"));
else hi=mid;
}
mid=(lo.add(hi)).divide(new BigInteger("2"));
//System.out.println(lo+" "+mid+" "+hi+" "+mid.pow(2));
System.out.println(mid);
}
}catch (NumberFormatException e){}
catch(IOException e){}
}
}