题解:SP15088 BFDIV - Ancient Aliens

· · 题解

原题中要求两个整数分别小于 10^{20} 所以可以用 __int128 存储。注意 __int128 需要自己实现输入输出。读入后直接输出 a \div b 和 a \bmod b 即可。

代码:

#include<bits/stdc++.h>
using namespace std;
string s[1000001];
inline __int128 read(){
    __int128 x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
inline void print(__int128 x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}
int main(){
    int T;
    cin>>T;
    while(T--){
        __int128 a,b;
        a=read(),b=read();
        print(a/b);
        cout<<" ";
        print(a%b);
        cout<<"\n";
    }
    return 0;
}