poj 2305(指定進位,大數模數)

來源:互聯網
上載者:User
題意:輸入一個進位b,在輸入兩個基於b進位的大整數 x,y ,求x%y的b進位結果。

http://162.105.81.212/JudgeOnline/problem?id=2305

函數:
String st = Integer.toString(num, base); // 把num當做10進位的數轉成base進位的st(base <= 35).
int num = Integer.parseInt(st, base); // 把st當做base進位,轉成10進位的int(parseInt有兩個參數,第一個為要轉的字串,第二個為說明是什麼進位).   
BigInter m = new BigInteger(st, base); // st是字串,base是st的進位.

//Added by abilitytao
1.如果要將一個大數以2進位形式讀入 可以使用cin.nextBigInteger(2); 
當然也可以使用其他進位方式讀入;
2.如果要將一個大數轉換成其他進位形式的字串 使用cin.toString(2);//將它轉換成2進位表示的字串

import java.math.*; import java.util.*;import java.math.BigInteger;public class Main{    public static void main (String[] args)throws Exception    {    Scanner in=new Scanner(System.in);    int b; BigInteger x,y;    while(in.hasNextInt())    {       b=in.nextInt();    if(b==0) break;    x=in.nextBigInteger(b);     y=in.nextBigInteger(b);    x=x.mod(y);    System.out.println(x.toString(b));    }    } }        

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.