Java大數

轉自:https://www.cnblogs.com/zufezzt/p/4794271.html

?

import java.util.*;
import java.math.*;
public class Main{public static void main(String args[]){Scanner cin = new Scanner(System.in);BigInteger a, b;//以文件EOF結束while (cin.hasNext()){a = cin.nextBigInteger();b = cin.nextBigInteger();System.out.println(a.add(b)); //大整數加法System.out.println(a.subtract(b)); //大整數減法System.out.println(a.multiply(b)); //大整數乘法System.out.println(a.divide(b)); //大整數除法(取整)System.out.println(a.remainder(b)); //大整數取模//大整數的比較if( a.compareTo(b) == 0 ) System.out.println("a == b"); //大整數a==belse if( a.compareTo(b) > 0 ) System.out.println("a > b"); //大整數a>belse if( a.compareTo(b) < 0 ) System.out.println("a < b"); //大整數a<b//大整數絕對值System.out.println(a.abs()); //大整數a的絕對值//大整數的冪int exponent=10;System.out.println(a.pow(exponent)); //大整數a的exponent次冪//返回大整數十進制的字符串表示
           System.out.println(a.toString());//返回大整數p進制的字符串表示int p=8;System.out.println(a.toString(p));}}
}

?

?

轉自:https://blog.csdn.net/morejarphone/article/details/51884888

HDU 1002

a+b大數版

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     void solve () {
 6         BigInteger a, b, c;
 7         Scanner cin = new Scanner(System.in);
 8         int t = cin.nextInt ();
 9         for (int i = 1; i <= t; i++) {
10             System.out.println ("Case " + i + ":");
11             a = cin.nextBigInteger ();
12             b = cin.nextBigInteger ();
13             System.out.println (a + " + " + b + " = " + a.add (b));
14             if (i != t) System.out.println ();
15         }
16     }
17     public static void main (String[] args) {
18         Main work = new Main();
19         work.solve ();
20     }
21 }

?

HDU 1042

階乘大數版

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     int maxn = 10005;
 6     void solve () {
 7         Scanner cin = new Scanner(System.in);
 8         int n;
 9         while (cin.hasNext()) {
10             n = cin.nextInt ();
11             BigInteger ans = BigInteger.valueOf (1);
12             for (int i = 2; i <= n; i++) {
13                 ans = ans.multiply (BigInteger.valueOf (i));
14             }
15             System.out.println (ans);
16         }
17     }
18     public static void main (String[] args) {
19         Main work = new Main();
20         work.solve ();
21     }
22 }

?

HDU 1297

f(n)=f(n?1)+f(n?2)+f(n?4)f(n)=f(n?1)+f(n?2)+f(n?4)

import java.math.*;
import java.util.*;public class Main {void solve () {Scanner cin = new Scanner(System.in);BigInteger[] ans = new BigInteger[1001];ans[1] = BigInteger.valueOf (1);ans[2] = BigInteger.valueOf (2);ans[3] = BigInteger.valueOf (4);ans[4] = BigInteger.valueOf (7);for (int i = 5; i <= 1000; i++) {ans[i] = ans[i-1].add (ans[i-2].add (ans[i-4]));}while (cin.hasNext ()) {int n = cin.nextInt ();System.out.println (ans[n]);}}public static void main (String[] args) {Main work = new Main();work.solve ();}
}

HDU 1753

高精度小數A+B,要去掉末尾的后導0.

import java.math.*;
import java.util.*;public class Main {void solve () {//BigInteger a, b, c;Scanner cin = new Scanner(System.in);BigDecimal a = BigDecimal.valueOf (0);BigDecimal b = BigDecimal.valueOf (0);while (cin.hasNext ()) {a = cin.nextBigDecimal ();b = cin.nextBigDecimal ();System.out.println (a.add (b).stripTrailingZeros().toPlainString());}}public static void main (String[] args) {Main work = new Main();work.solve ();}
}

?

轉載于:https://www.cnblogs.com/upc201713/p/8979347.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389746.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389746.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389746.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2027. 轉換字符串的最少操作次數

2027. 轉換字符串的最少操作次數 給你一個字符串 s &#xff0c;由 n 個字符組成&#xff0c;每個字符不是 ‘X’ 就是 ‘O’ 。 一次 操作 定義為從 s 中選出 三個連續字符 并將選中的每個字符都轉換為 ‘O’ 。注意&#xff0c;如果字符已經是 ‘O’ &#xff0c;只需要保持…

bigquery_到Google bigquery的sql查詢模板,它將您的報告提升到另一個層次

bigqueryIn this post, we’re sharing report templates that you can build with SQL queries to Google BigQuery data.在本文中&#xff0c;我們將分享您可以使用SQL查詢為Google BigQuery數據構建的報告模板。 First, you’ll find out about what you can calculate wit…

分類樹/裝袋法/隨機森林算法的R語言實現

原文首發于簡書于[2018.06.12] 本文是我自己動手用R語言寫的實現分類樹的代碼&#xff0c;以及在此基礎上寫的袋裝法&#xff08;bagging&#xff09;和隨機森林&#xff08;random forest&#xff09;的算法實現。全文的結構是&#xff1a; 分類樹 基本知識predginisplitrules…

數據科學學習心得_學習數據科學時如何保持動力

數據科學學習心得When trying to learn anything all by yourself, it is easy to lose motivation and get thrown off track.嘗試自己學習所有東西時&#xff0c;很容易失去動力并偏離軌道。 In this article, I will provide you with some tips that I used to stay focus…

用php當作cat使用

今天&#xff0c;本來是想敲 node test.js 執行一下&#xff0c;test.js文件&#xff0c;結果 慣性的敲成了 php test.js, 原文輸出了 test.js的內容。 突然覺得&#xff0c;這東西 感覺好像是 cat 命令&#xff0c;嘿嘿&#xff0c;以后要是ubuntu 上沒裝 cat &#xff0c; …

建信01. 間隔刪除鏈表結點

建信01. 間隔刪除鏈表結點 給你一個鏈表的頭結點 head&#xff0c;每隔一個結點刪除另一個結點&#xff08;要求保留頭結點&#xff09;。 請返回最終鏈表的頭結點。 示例 1&#xff1a; 輸入&#xff1a;head [1,2,3,4] 輸出: [1,3] 解釋&#xff1a; 藍色結點為刪除的結點…

python安裝Crypto:NomodulenamedCrypto.Cipher

python 安裝Crypto時出現的錯誤:NomodulenamedCrypto.Cipher 首先直接pip install Crypto 這時會在lib/site-packages/ 文件夾下生成crypto文件夾&#xff0c;將其重命名為Crypto ...然而這個文件夾下沒有Cipher模塊&#xff0c;還需要pip安裝一個pycrypto&#xff0c;不過wind…

python多項式回歸_在python中實現多項式回歸

python多項式回歸Video Link影片連結 You can view the code used in this Episode here: SampleCode您可以在此處查看 此劇 集中使用的代碼&#xff1a; SampleCode 導入我們的數據 (Importing our Data) The first step is to import our data into python.第一步是將我們的…

Uboot 命令是如何被使用的?

有什么問題請 發郵件至syyxyoutlook.com, 歡迎交流~ 在uboot代碼中命令的模式是這個樣子&#xff1a; 這樣是如何和命令行交互的呢&#xff1f; 在command.h 中, 我們可以看到如下宏定義 將其拆分出來&#xff1a; #define U_BOOT_CMD(name,maxargs,rep,cmd,usage,help) \ U_…

2029. 石子游戲 IX

2029. 石子游戲 IX Alice 和 Bob 再次設計了一款新的石子游戲。現有一行 n 個石子&#xff0c;每個石子都有一個關聯的數字表示它的價值。給你一個整數數組 stones &#xff0c;其中 stones[i] 是第 i 個石子的價值。 Alice 和 Bob 輪流進行自己的回合&#xff0c;Alice 先手…

大數據可視化應用_在數據可視化中應用種族平等意識

大數據可視化應用The following post is a summarized version of the article accepted to the 2020 Visualization for Communication workshop as part of the 2020 IEEE VIS conference to be held in October 2020. The full paper has been published as an OSF Preprint…

Windows10電腦系統時間校準

有時候新安裝電腦系統&#xff0c;系統時間不對&#xff0c;需要主動去校準系統時間。1、點擊時間 2、日期和時間設置 3、其他日期、時間和區域設置 4、設置時間和日期 5、Internet 時間 6、點擊立即更新&#xff0c;如果更新失敗就查電腦是否已聯網&#xff0c;重試點擊立即更…

webpack問題

Cannot find module webpack/lib/node/NodeTemplatePlugin 全局&#xff1a;npm i webpack -g npm link webpack --save-dev 轉載于:https://www.cnblogs.com/doing123/p/8994269.html

397. 整數替換

397. 整數替換 給定一個正整數 n &#xff0c;你可以做如下操作&#xff1a; 如果 n 是偶數&#xff0c;則用 n / 2替換 n 。 如果 n 是奇數&#xff0c;則可以用 n 1或n - 1替換 n 。 n 變為 1 所需的最小替換次數是多少&#xff1f; 示例 1&#xff1a; 輸入&#xff1a;…

pd種知道每個數據的類型_每個數據科學家都應該知道的5個概念

pd種知道每個數據的類型意見 (Opinion) 目錄 (Table of Contents) Introduction 介紹 Multicollinearity 多重共線性 One-Hot Encoding 一站式編碼 Sampling 采樣 Error Metrics 錯誤指標 Storytelling 評書 Summary 摘要 介紹 (Introduction) I have written about common ski…

td

單元格td設置padding&#xff0c;而不能設置margin。轉載于:https://www.cnblogs.com/fpcbk/p/9617629.html

清除浮動的幾大方法

對于剛接觸到html的一些人經常會用到浮動布局&#xff0c;但對于浮動的使用和清除浮動來說是大為頭痛的&#xff0c;在這里介紹幾個關于清除浮動的的方法。如果你說你要的就是浮動為什么要清除浮動的話&#xff0c;我就真的無言以對了&#xff0c;那你就當我沒說。 關于我們在布…

xgboost keras_用catboost lgbm xgboost和keras預測財務交易

xgboost kerasThe goal of this challenge is to predict whether a customer will make a transaction (“target” 1) or not (“target” 0). For that, we get a data set of 200 incognito variables and our submission is judged based on the Area Under Receiver Op…

2017. 網格游戲

2017. 網格游戲 給你一個下標從 0 開始的二維數組 grid &#xff0c;數組大小為 2 x n &#xff0c;其中 grid[r][c] 表示矩陣中 (r, c) 位置上的點數。現在有兩個機器人正在矩陣上參與一場游戲。 兩個機器人初始位置都是 (0, 0) &#xff0c;目標位置是 (1, n-1) 。每個機器…

HUST軟工1506班第2周作業成績公布

說明 本次公布的成績對應的作業為&#xff1a; 第2周個人作業&#xff1a;WordCount編碼和測試 如果同學對作業成績存在異議&#xff0c;在成績公布的72小時內&#xff08;截止日期4月26日0點&#xff09;可以進行申訴&#xff0c;方式如下&#xff1a; 畢博平臺的第二周在線答…