Poj 2305 (in hexadecimal notation, modulo of large numbers)

Source: Internet
Author: User
Enter a base B, and then input two big integers x and y based on the base B to calculate the base B result of X % Y.

Http: // 162.105.81.212/judgeonline/problem? Id = 2305

Function:
String ST = integer. tostring (Num, base); // convert num into base (base <= 35 ).
Int num = integer. parseint (St, base); // Use ST as the base and convert it to a 10-digit int (parseint has two parameters, and the first is the string to be converted, the second is to explain what the hexadecimal format is ).
Biginter M = new biginteger (St, base); // st is a string, and base is the base.

// Added by abilitytao
1. If you want to read a large number in binary format, you can use cin. nextbiginteger (2 );
Of course, you can also use other hexadecimal methods to read data;
2. If you want to convert a large number to a string in other hexadecimal forms, use cin. tostring (2); // convert it to a string in binary format.

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));    }    } }        

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.