上进小青年

导航

大整数求余

对于大整数(此处指长度超过100的一组以数字组成的字符串),求出这个数对于某个数字n的余数;

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     int n;
 9     char s[105];
10     while(cin>>s){
11 
12         cin>>n;
13         int m=0;
14         for(int i=0;i<strlen(s);i++){
15             m=m*10+s[i]-'0';
16             m%=n;
17         }
18         if(m==0)cout<<"Yes"<<endl;
19         else cout<<m<<endl;
20 
21     }
22 }
View Code

 

posted on 2016-08-18 14:54  上进小青年  阅读(205)  评论(0编辑  收藏  举报