HDU 1212 Big Number (C + + large numbers modulo) (Java large number of applications)

Source: Internet
Author: User

Big number

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1212

--Daily Online, welcome message to talk about.

Main topic:

Give you two number n1,n2. Where N1 is very large, n1%n2 value.

Knowledge Points:

① Qin Jiushao formula:
Example: 1314 = ((1*10+3) *10+1) *10+4

② (a*b)%c = = (a%c) * (b%c), (a+b)%c = = (a%c) + (b%c).

Ideas:

Every step of the mold can be taken.

C + + AC code:
1#include <iostream>2#include <string>3 using namespacestd;4 5 intMain ()6 {7     stringS1;8     inty;9      while(cin>>s1>>y)Ten     { One         intsum=s1[0]-'0'; A          for(intI=1; I<s1.size (); i++) -         { -Sum= (sum*Ten+s1[i]-'0')%y; the         } -cout<<sum<<Endl; -     } -     return 0; +}
Java AC Code:
1 ImportJava.util.Scanner;2 ImportJava.math.BigInteger;3  Public classMain {4      Public Static voidMain (string[] args) {5Scanner SCN =NewScanner (system.in);6 BigInteger Bint1,bint2;7          while(Scn.hasnext ()) {8Bint1 =Scn.nextbiginteger ();9Bint2 =Scn.nextbiginteger ();Ten System.out.println (Bint1.remainder (Bint2)); One         } ASystem.exit (0); -     } -}

2017-07-23 14:26:23-2017-07-23 14:41:00

HDU 1212 Big Number (C + + large numbers modulo) (Java large number of applications)

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.