hdu1212(大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212

题意:给出两个数a, b,求a%b;

思路:(c+d)%e=c%e+d%e,(c*d)%e=(c%e*d%e)%e;

代码:


 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #define ll long long
 5 #define MAXN 1000+10
 6 using namespace std;
 7 
 8 int main(void){
 9     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
10     int b;
11     char a[MAXN];
12     while(~scanf("%s%d", a, &b)){
13         int ans=0, cnt=1;
14         for(int i=0; i<strlen(b); i++){
15             int gg=a[i]-'0';
16             ans=(ans*10+gg)%b;
} 17 printf("%d ", ans); 18 } 19 return 0; 20 }


 

据说java大数很厉害。。然后get了一下。。果然威力无穷。。。

代码:

 1 import java.math.BigDecimal;
 2 import java.util.Scanner;
 3 
 4 public class Main{
 5     public static void main(String args[]){
 6         Scanner scan = new Scanner(System.in);
 7         while(scan.hasNext()){
 8             BigDecimal a = scan.nextBigDecimal();
 9             int b = scan.nextInt();
10             System.out.println(a.remainder(new BigDecimal(b)));
11         }
12     }
13 }
原文地址:https://www.cnblogs.com/geloutingyu/p/5989883.html