Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1212
Test instructions: Give two number A, B, seek a%b;
Idea: (c+d)%e=c%e+d%e, (c*d)%e= (c%e*d%e)%e;
Code:
1#include <iostream>2#include <stdio.h>3#include <string.h>4 #definell Long Long5 #defineMAXN 1000+106 using namespacestd;7 8 intMainvoid){9Ios::sync_with_stdio (false), Cin.tie (0), Cout.tie (0);Ten intb; One CharA[MAXN]; A while(~SCANF ("%s%d", A, &b)) { - intans=0, cnt=1; - for(intI=strlen (a)-1; i>=0; i--){ the intGg= (a[i]-'0')*CNT; -ans= (ANS+GG)%b; -cnt=cnt*Ten%b; - } +printf"%d\n", ans); - } + return 0; A}
It is said that Java large number is very bad. Then get a bit. The Power is endless ...
Code:
1 ImportJava.math.BigDecimal;2 ImportJava.util.Scanner;3 4 Public classmain{5 Public Static voidMain (String args[]) {6Scanner scan =NewScanner (system.in);7 while(Scan.hasnext ()) {8BigDecimal A =scan.nextbigdecimal ();9 intb =scan.nextint ();TenSystem.out.println (A.remainder (NewBigDecimal (b))); One } A } -}
hdu1212 (large number modulus)