Submission #1677984


Source Code Expand

#include <cstdio>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<i64, i64> pii;

#define fi first
#define se second

vector<pii> vec[100];
i64 f[100];

int F(i64 a, i64 b) {
	if (a < b) swap(a, b);
	return !b ? 0 : F(b, a % b) + 1;
}

int main() {
	f[0] = 1, f[1] = 1;
	int n = 1;

	
	while (f[n] <= 1e18) {
		++n;
		f[n] = f[n - 1] + f[n - 2];
	}
	f[n + 1] = f[n];
	--n;

	vec[0].push_back(pii(0, 1));
	vec[0].push_back(pii(0, 2));
	iter(i, n) {
		for (pii p : vec[i - 1]) {
			i64 a = p.fi, b = p.se;
		//	if (i == 4) printf("[%lld %lld] %d %d %lld\n", a, b, i-1, F(a, b), f[i+1]);
			assert(F(a, b) == i - 1);

//			printf("%d [%lld %lld]", i, a, b);
			for (; a + b <= f[i + 2]; a += b) {
				//gcd(f[i+2],f
				if (F(b, a + b) == i) vec[i].push_back(pii(b, a + b));
			}
		}
	}
	int q;
	scanf("%d", &q);
	iter(id, q) {
		i64 a, b;
		scanf("%lld%lld", &a, &b);
		if (a > b) swap(a, b);
		int ans = 1; i64 cnt = 0;
		iter(i, n) {
			if (a >= f[i] && b >= f[i + 1]) ans = i;
			else break;
		}
		printf("%d ", ans);
		for (pii p : vec[ans - 1]) {
			if (p.se <= a && p.fi + p.se <= b && p.fi != p.se) cnt = (cnt + (b - p.fi) / p.se) % mod;
			swap(a, b);
			if (p.se <= a && p.fi + p.se <= b && p.fi != p.se) cnt = (cnt + (b - p.fi) / p.se) % mod;
			swap(a, b);
			
		}
		printf("%lld\n", ans != 1 ? cnt : a * b % mod);
	}
	//
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:53:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
                 ^
./Main.cpp:56:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &a, &b);
                            ^

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 226 ms 3328 KB
02.txt AC 225 ms 3328 KB
03.txt AC 225 ms 3328 KB
04.txt AC 225 ms 3328 KB
05.txt AC 232 ms 3328 KB
06.txt AC 228 ms 3328 KB
07.txt AC 225 ms 3328 KB
08.txt AC 226 ms 3328 KB
09.txt AC 226 ms 3328 KB
10.txt AC 226 ms 3328 KB
11.txt AC 301 ms 1920 KB
12.txt AC 300 ms 1920 KB
13.txt AC 161 ms 1920 KB
14.txt AC 161 ms 1920 KB
15.txt AC 186 ms 4096 KB
16.txt AC 186 ms 4096 KB
17.txt AC 148 ms 3840 KB
18.txt AC 148 ms 3840 KB
19.txt AC 367 ms 3584 KB
20.txt AC 367 ms 3584 KB
21.txt AC 7 ms 384 KB
22.txt AC 7 ms 384 KB
23.txt AC 7 ms 384 KB
24.txt AC 7 ms 384 KB
s1.txt AC 7 ms 384 KB
s2.txt AC 7 ms 384 KB