Submission #1332901


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define dig(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;

const int mod = 1e9+7;
const int maxn = 105;
const int N = 85;

int T;
LL f[maxn];
vector<pair<LL, LL> > excel[maxn];

void Init()
{
	scanf("%d", &T);
	f[0] = 1;
	f[1] = 1;
	for (int i = 2; i <= N + 2; ++i) {
		f[i] = f[i - 1] + f[i - 2];
	}
}

int gcd_count(LL x, LL y)
{
	int cnt = 0;
	if (x > y) swap(x, y);
	while (x) {
		x ^= y ^= x ^= y %= x;
		++cnt;
	}
	return cnt;
}

void Prepare()
{
	vector<pair<LL, LL> >::iterator it, p;
	LL x, y;
	excel[1].push_back(make_pair(1, 2));
	excel[1].push_back(make_pair(1, 3));
	for (int i = 1; i < N; ++i) {
		for (p = excel[i].begin(); p != excel[i].end(); ++p) {
			x = (*p).first;
			y = (*p).second;
			for (int j = 1; j <= 2; ++j) {
				if (y * j + x > f[i + 3]) break;
				if (gcd_count(y, y * j + x) == i + 1) {
					excel[i + 1].push_back(make_pair(y, y * j + x));
				}
			}
		}
		sort(excel[i + 1].begin(), excel[i + 1].end());
		it = unique(excel[i + 1].begin(), excel[i + 1].end());
		excel[i + 1].resize(distance(excel[i + 1].begin(), it));
	}
	/*for (int i = 1; i <= N; ++i) {
		dig("%d\n", (int)excel[i].size());
		}*/
}

void Solve()
{
	LL X, Y, x, y;
	int ans;
	LL sum = 0;
	vector<pair<LL, LL> >::iterator it;
	while (T--) {
		cin >> X >> Y;
		if (X > Y) swap(X, Y);
		ans = 1;
		for (int i = 2; i <= N; ++i) {
			if (X >= f[i] && Y >= f[i + 1]) {
				ans = i;
			}
			else {
				break;
			}
		}
		sum = 0;
		if (ans == 1) {
			sum = (X % mod * Y % mod) % mod;
		}
		else {
			for (it = excel[ans - 1].begin(); it != excel[ans - 1].end(); ++it) {
				x = (*it).first;
				y = (*it).second;
				if (X >= y) {
					(sum += (Y - x) / y) %= mod;
				}
				if (Y >= y) {
					(sum += (X - x) / y) %= mod;
				}
			}
		}
		cout << ans << ' ' << sum << endl;
	}
}

int main()
{
	Init();
	Prepare();
	Solve();
	return 0;
}

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User luoyuchu
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 2000 Byte
Status AC
Exec Time 1348 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘void Init()’:
./Main.cpp:18:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &T);
                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1700 / 1700
Status
AC × 2
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 965 ms 3328 KB
02.txt AC 974 ms 3328 KB
03.txt AC 970 ms 3328 KB
04.txt AC 964 ms 3328 KB
05.txt AC 971 ms 3328 KB
06.txt AC 971 ms 3328 KB
07.txt AC 974 ms 3328 KB
08.txt AC 979 ms 3328 KB
09.txt AC 966 ms 3328 KB
10.txt AC 965 ms 3328 KB
11.txt AC 1348 ms 1920 KB
12.txt AC 1345 ms 1920 KB
13.txt AC 777 ms 1920 KB
14.txt AC 800 ms 1920 KB
15.txt AC 910 ms 4096 KB
16.txt AC 899 ms 4096 KB
17.txt AC 770 ms 3840 KB
18.txt AC 937 ms 3840 KB
19.txt AC 1225 ms 3584 KB
20.txt AC 1263 ms 3584 KB
21.txt AC 5 ms 384 KB
22.txt AC 5 ms 384 KB
23.txt AC 5 ms 384 KB
24.txt AC 5 ms 384 KB
s1.txt AC 5 ms 384 KB
s2.txt AC 5 ms 384 KB