ARC004のwriterやってました
「Cは long long と見せかけて実はそれでもオーバーフローするから多倍長を使いました。」と言われた。
でもwriter解では多倍長を使ってない。
Problem C.
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cmath> #include <vector> #include <string> using namespace std; typedef long long LL; LL func(LL n, LL num, LL den){ LL a = __gcd(n, den); n /= a; den /= a; LL b = __gcd(num, den); num /= b; den /= b; if(den > 1) return -1; return num * n; } int main(void){ LL num, den, n; bool flag = true; scanf ("%lld/%lld", &num, &den); n = (num * 2 + den) / den - 1; LL x = func(n, num, den); if (n > 0 && x != -1){ cout << n << " " << n * (n + 1) / 2 - x << endl; flag = false; } n++; x = func(n, num, den); if (x != -1){ cout << n << " " << n * (n + 1) / 2 - x << endl; flag = false; } if (flag) cout << "Impossible" << endl; return 0; }
ヽ( ・∀・)ノ┌┛ガッ[謝罪会見会場]