QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737878#9622. 有限小数LmR308RE 0ms0kbC++171.8kb2024-11-12 17:03:142024-11-12 17:03:20

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 17:03:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-12 17:03:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int128 __int128_t
#define int long long
#define PII pair<int, int>
#define PDD pair<double, double>
#define fi first    
#define se second
#define lowbit(x) x & -x
#define all(x) x.begin(), x.end()
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define ull unsigned long long
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 10, M = 5e6 + 10, mod = 998244353;
const double eps = 1e-8;

int t, n, m, k;	
string sr;

int exgcd(int a, int b, int &x, int &y) {
	if (!b) {
		x = 1, y = 0;
		return a;
	}
	int d = exgcd(b, a % b, y, x);
	y -= (a / b) * x;
	return d;
}

void solve() {
	int a, b;
	cin >> a >> b;
	int temp = b;
	while (temp % 2 == 0) temp /= 2;
	while (temp % 5 == 0) temp /= 5;
	int resc = INF, resd = INF, tlc = b / temp;
	for (int i = 0; i <= 40; i++) {
		int te = 1;
		for (int j = 0; j < i; j++) te = te * 2;
		for (int j = 0; j <= 40; j++) {
			if (te >= 1e16 / temp) break;
			int d = te * temp;
			int lc = temp * temp, x, y;
			int comd = exgcd(b, lc, x, y), m = (-a * d % lc + lc) % lc;
			if (m % comd == 0) {
				int tempc = m / comd * x;
				assert(tempc > 0);
				bool flag = false;
				int sum = a * d + b * tempc;
				if (sum % (b * d) == 0) flag = true;
				if (sum != 0 && (b * d) % sum == 0) {
					int g = (b * d) / sum;
					while (g % 2 == 0) g /= 2;
					while (g % 5 == 0) g /= 5;
					if (g == 1) flag = true;
				}
				if (resc > tempc && flag) {
					resc = tempc;
					resd = d;
				}
			}
			te *= 5;
		}
	}
	cout << resc << " " << resd << "\n";
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	cout.setf(ios::fixed), cout.precision(10);
	t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}	

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
1 2
2 3
3 7
19 79

output:


result: