Large Division LightOJ - 1214
考察:高精除
为什么在数论题单看见这道题...
坑点:
- 本蒟蒻WA一次的原因可能是存在多个负号的坑爹数据,改了这个AC了..不太清楚是不是因为改了别的地方
1 #include <iostream> 2 #include <algorithm> 3 #include <vector> 4 #include <cstring> 5 using namespace std; 6 typedef long long ll; 7 const int N = 210; 8 char a[N],b[N]; 9 ll base; 10 vector<int> A; 11 bool solve() 12 { 13 ll r = 0; 14 if(base<0) base = -base; 15 for(int i=A.size()-1;i>=0;i--) 16 { 17 r = r*10+A[i]; 18 r%=base; 19 } 20 if(!r) return true; 21 else return false; 22 } 23 int main() 24 { 25 // freopen("in.txt","r",stdin); 26 int T,kcase = 0; 27 scanf("%d",&T); 28 while(T--) 29 { 30 printf("Case %d: ",++kcase); 31 scanf("%s%s",a,b); 32 int alen = strlen(a),blen = strlen(b); 33 A.clear(); 34 int ta = 0; 35 while(a[ta]=='-') ta++; 36 for(int i=alen-1;i>=ta;i--) A.push_back(a[i]-'0'); 37 base = stoll(b); 38 if(solve()) printf("divisible\n"); 39 else printf("not divisible\n"); 40 } 41 return 0; 42 }