基准时间限制:4 秒 空间限制:131072 KB 分值: 320 难度:7级算法题
 收藏
 关注
给出一个大整数N,求不大于N的平方根的最大整数。例如:N = 8,2 * 2 < 8,3 * 3 > 8,所以输出2。

Input
给出一个大数N(N的长度 <= 100000)。
Output
输出不大于Sqrt(n)的最大整数。
Input示例
9
Output示例
3

java大整数套牛顿迭代法

牛顿迭代法在计算方法这门课里学过,但是现在记忆已经有些模糊了

import java.math.BigInteger;
import java.math.*;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.*;
public class Main
{
public static void bigSqrt(){
Scanner cin=new Scanner(System.in);
String s=cin.next();
BigInteger remain=BigInteger.ZERO;
BigInteger odd=BigInteger.ZERO;
BigInteger ans=BigInteger.ZERO;
// remain=BigInteger.ZERO;
// odd=BigInteger.ZERO;
// ans=BigInteger.ZERO;
int group=0,k=0;
if(s.length()%2==1)
{
group=s.charAt(0)-'0';
k=-1;
}
else
{
group=(s.charAt(0)-'0')*10+s.charAt(1)-'0';
k=0;
}
for(int j=0;j<(s.length()+1)/2;j++)
{
if(j!=0)
group=(s.charAt(j*2+k)-'0')*10+s.charAt(j*2+k+1)-'0';
odd=BigInteger.valueOf(20).multiply(ans).add(BigInteger.ONE);
remain=BigInteger.valueOf(100).multiply(remain).add(BigInteger.valueOf(group));
int count=0;
while(remain.compareTo(odd)>=0)
{
count++;
remain=remain.subtract(odd);
odd=odd.add(BigInteger.valueOf(2));
}
ans=ans.multiply(BigInteger.TEN).add(BigInteger.valueOf(count));
}
System.out.println(ans);
cin.close();
return;
}
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
//int t=cin.nextInt(); bigSqrt(); cin.close();
}
}

51nod 1166 大数开平方的更多相关文章

  1. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  2. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

  3. 51NOD 1027 大数乘法

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题   给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B (A,B ...

  4. 快速切题 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 n ...

  5. 51Nod 1028 大数乘法 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 分析: FFT/NTT板子题... 代码: NTT板子: #inc ...

  6. 51nod 1029 大数除法

    1029 大数除法 基准时间限制:4 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  关注 给出2个大整数A,B,计算A / B和A Mod B的结果. Input 第1 ...

  7. 大数高精度加减乘除 51nod 1005 大数加法

    1005 大数加法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出2个大整数A,B,计算A+B的结果. Input 第1行:大数A 第2行:大数B ...

  8. FFT/NTT [51Nod 1028] 大数乘法 V2

    题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...

  9. 51nod 1028 大数乘法 V2 【FFT模板题】

    题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...

随机推荐

  1. next_permitation

    了解一个C++ STL的函数 next_permitation 可用于生成全排列 如下例子 #include <iostream> #include <stdio.h> #in ...

  2. Codeforces913E. Logical Expression

    现有串x=11110000,y=11001100,z=10101010,通过这三个串只用与或非三种操作到达给定的串,优先级非>或>与,可以加括号,问表达式最短的里面字典序最小的是谁,有&l ...

  3. PatentTips - Hierarchical RAID system including multiple RAIDs

    BACKGROUND OF THE INVENTION The present invention relates to a storage system offering large capacit ...

  4. mysql 之 Workbench的使用

    mysql 之 Workbench的使用 (1)简介 MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用My ...

  5. android中SQLite实现

    SQLite操作类: package com.example.administrator.myapplication; import android.content.Context; import a ...

  6. POJ 3686_The Windy's

    题意: N个工件要在M个工厂加工,一个工件必须在一个工厂做完,工厂一次只能处理一个工件.给定每个工件在每个工厂加工所需时间,求出每个工件加工结束的最小时间平均值. 分析: 工厂一次只能处理一个工件,那 ...

  7. 002 static and default route

    r2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1 r1(config)#ip route 192.168.3.0 255.255.25 ...

  8. linux发行版的用户交互

    1 cli,即command line interface 纯命令行的交互方式,该命令行界面是由shell提供的. linux内核本身也自带了一个console,即linux console,它是基于 ...

  9. a high-level neural networks AP

    Keras Documentation https://keras.io/ You have just found Keras. Keras is a high-level neural networ ...

  10. 60分钟Python快速学习

    之前和同事谈到Python,每次下班后跑步都是在听他说,例如Python属于“胶水语言啦”,属于“解释型语言啦!”,是“面向对象的语言啦!”,另外没有数据类型,逻辑全靠空格缩进表示等. 今天自己用了6 ...