zoukankan      html  css  js  c++  java
  • 快速切题 sgu 111.Very simple problem 大数 开平方 难度:0 非java:1

    111.Very simple problem

    time limit per test: 0.5 sec. 
    memory limit per test: 4096 KB


    You are given natural number X. Find such maximum integer number that it square is not greater than X.


    Input

    Input file contains number X (1≤X≤101000).


    Output

    Write answer in output file.


    Sample Input

    16


    Sample Output

    4

     开平方的方法懒得写,索性二分,可能的话将来回来写写

    实际用时:11min

    import java.io.*;
    import java.math.BigInteger;
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Main {
    	public static void main(String []args) throws IOException{
    		BigInteger X;
    		Scanner scanner=new Scanner(System.in);
    		X=scanner.nextBigInteger();
    		if(X.compareTo(BigInteger.ONE)==0){
    			System.out.println("1");
    			return ;
    		}
    		BigInteger l=BigInteger.ZERO,r=X;
    		while(r.compareTo(l.add(BigInteger.ONE))==1){
    			BigInteger mid=l.add(r).shiftRight(1);
    			int fl=X.compareTo(mid.multiply(mid));
    			if(fl==0){
    				l=mid;
    				break;
    			}
    			else if(fl==-1){
    				r=mid;
    			}
    			else {
    				l=mid;
    			}
    		}
    		System.out.println(l);
    	}
    }
    

      

     

  • 相关阅读:
    Express 框架中 使用ejs
    Nodejs操作MongoDB数据库
    MongoDB基础操作
    node中的包、npm和模块
    background
    animation
    transition
    transform
    【SpringCloud】各种组件的更新情况
    【SpringCloud】版本选择
  • 原文地址:https://www.cnblogs.com/xuesu/p/4003733.html
Copyright © 2011-2022 走看看