大数对小数的求余和商
发布时间:2020-12-14 03:37:10 所属栏目:大数据 来源:网络整理
导读:用到了同余定理:(a+b)%c=(a%c+b%c)%c, 并在取余之前求各个位置的商; 题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudgeItemid=8page=show_problemproblem=1435 #includeiostream#includecstdio#includecstringusing namespace std;cons
用到了同余定理:(a+b)%c=(a%c+b%c)%c, 并在取余之前求各个位置的商; 题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1435
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int nmax=10000000; char num1[nmax]; char num[nmax]; int main() { long long b; char ope; while(~scanf("%s %c %lld",num1,&ope,&b)) { memset(num,sizeof(num)); int len=strlen(num1); long long a=0,k=0; for(int i=0;i<len;i++) { a=a*10+(num1[i]-'0'); num[k++]=a/b+'0';//取余前求商 a%=b; } if(ope=='%') cout<<a<<endl; else { int i=0; while(num[i]=='0') i++; if(num[i]==0) i--; for(;i<k;i++) cout<<num[i]; cout<<endl; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |