Big Number
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212
——每天在线,欢迎留言谈论。
题目大意:
给你两个数 n1,n2。其中n1 很大很大,n1%n2的值。
知识点:
①秦九韶公式:
例:1314= ((1*10+3)*10+1)*10+4
②(a*b)%c == (a%c)*(b%c) 、(a+b)%c == (a%c)+(b%c) 。
思路:
每步取模即可。
C++ AC代码:
#include <iostream>
#include <string>
using namespace std; int main()
{
string s1;
int y;
while(cin>>s1>>y)
{
int sum=s1[]-'';
for(int i=;i<s1.size();i++)
{
sum=(sum*+s1[i]-'')%y;
}
cout<<sum<<endl;
}
return ;
}
Java AC代码:
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
BigInteger bint1,bint2;
while(scn.hasNext()){
bint1 = scn.nextBigInteger();
bint2 = scn.nextBigInteger();
System.out.println(bint1.remainder(bint2));
}
System.exit(0);
}
}
2017-07-23 14:26:23 -> 2017-07-23 14:41:00