国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Java > 正文

openjudge4010: 2011(java BigInteger)

2019-11-06 06:02:18
字體:
供稿:網(wǎng)友

http://bailian.openjudge.cn/PRactice/4010

題意:已知長(zhǎng)度最大為200位的正整數(shù)n,請(qǐng)求出2011^n的后四位。

第一次用java BigInteger類,參考了一下BigInteger的一些方法,就可以寫出大數(shù)快速冪。

import java.util.Scanner;import java.math.BigInteger;public class Main {    static BigInteger base = new BigInteger("2011");    static BigInteger MOD = new BigInteger("10000");    static BigInteger zero = new BigInteger("0");    static BigInteger one = new BigInteger("1");    static BigInteger two = new BigInteger("2");    public static BigInteger FastMul(BigInteger n){        if(n.equals(one)){            return base;        }        if(n.mod(two).equals(zero)){            BigInteger ret = FastMul(n.divide(two));            return ret.multiply(ret).mod(MOD);        }        else{            return base.multiply(FastMul(n.subtract(one))).mod(MOD);        }    }    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int k = sc.nextInt();        for(int i=0; i<k; ++i){            BigInteger n = sc.nextBigInteger();            BigInteger ans = FastMul(n);            System.out.println(ans.mod(MOD));        }    }}

ss


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沿河| 昂仁县| 丹凤县| 珠海市| 通海县| 广汉市| 达州市| 泸溪县| 重庆市| 杂多县| 梓潼县| 喀喇沁旗| 海安县| 三原县| 新昌县| 永济市| 广元市| 无为县| 章丘市| 临高县| 南华县| 宾阳县| 高要市| 沂源县| 五大连池市| 阿拉善右旗| 昌平区| 汕头市| 孟连| 东港市| 延吉市| 新蔡县| 徐州市| 鹿邑县| 石棉县| 农安县| 界首市| 民和| 介休市| 象州县| 嫩江县|