题目链接: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;
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#define ll long long
#define MAXN 1000+10
using namespace std; int main(void){
ios::sync_with_stdio(false), cin.tie(), cout.tie();
int b;
char a[MAXN];
while(~scanf("%s%d", a, &b)){
int ans=, cnt=;
for(int i=; i<strlen(b); i++){
int gg=a[i]-'';
ans=(ans*+gg)%b;
}
printf("%d\n", ans);
}
return ;
}
据说java大数很厉害。。然后get了一下。。果然威力无穷。。。
代码:
import java.math.BigDecimal;
import java.util.Scanner; public class Main{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
BigDecimal a = scan.nextBigDecimal();
int b = scan.nextInt();
System.out.println(a.remainder(new BigDecimal(b)));
}
}
}