K - Large Division 判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余;
/** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余; */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; char a[210]; bool solve(ll mod) { ll r = 0; for(int i = 0; a[i]!='\0'; i++){ if(a[i]=='-') continue; r = r*10+(a[i]-'0'); r %= mod; } return r==0; } int main() { int T, cas=1; ll mod; cin>>T; while(T--) { scanf("%s%lld",a,&mod); if(mod<0) mod = -mod; printf("Case %d: %s\n",cas++,solve(mod)?"divisible":"not divisible"); } return 0; }
posted on 2017-03-31 12:21 hnust_accqx 阅读(177) 评论(0) 编辑 收藏 举报