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)