加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

poj 2305(指定进制,大数取模)

发布时间:2020-12-14 04:03:00 所属栏目:大数据 来源:网络整理
导读:题意:输入一个进制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.pa

题意:输入一个进制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));
    	}
    } 
}        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读