跳到正文

题解

题解:SP15088 BFDIV - Ancient Aliens

Winter_Cube约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年8月6日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 2 分钟
题目
SP15088

版本

  1. v1当前

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

代码:

C++
#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;
}
原文