1103: PIPI的数学题I

使用同余定理

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char n[10010];
ll  p;
int main(){
	while(scanf("%s%d",n+1,&p)!=EOF){
		//cout<<n+1<<p;
		int l=strlen(n+1);
		ll ans=0;
		for(int i=1;i<=l;i++){
			ans=((ans*10)%p+n[i]-'0')%p;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
posted @ 2026-03-14 22:24  peter_shen  阅读(8)  评论(0)    收藏  举报