Submission #1752534


Source Code Expand

// Kenus the Ancient Greek
// * frank_c1
// * 2017 / 11 / 08

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

const int maxw = 87;
const int mo = (int)(1e9) + 7;
LL f[maxw + 10];
vector<pair<LL, LL> > g[maxw + 5];

void gen() {
	f[0] = f[1] = 1;
	for (int i = 2; i <= maxw + 3; ++i) f[i] = f[i - 1] + f[i - 2];
	g[0].push_back(make_pair(1, 1));
	for (int i = 0; i < maxw; ++i) {
		for (int j = 0; j < (int)g[i].size(); ++j) {
			LL y = g[i][j].first, x = g[i][j].second + y;
			while (x <= f[i] + f[i + 3]) {
				g[i + 1].push_back(make_pair(x, y)); x += y;
			}
		}
	}
}

LL calc(LL n, LL m, int p) {
	LL ret = 0;
	for (int j = 0; j < (int)g[p - 1].size(); ++j) {
		LL x = g[p - 1][j].first, y = g[p - 1][j].second;
		if (x <= m) (ret += (n - y) / x) %= mo;
	} return ret;
}

void solve() {
	LL n, m; 
	scanf("%lld%lld", &n, &m);
	if (n < m) swap(n, m);
	if (n == 2 && m == 2) {
		printf("1 4\n"); return;
	}
	if (m == 1) {
		printf("1 %d\n", n % mo); return;
	}
	int p = 2, res= 0;
	for (; n >= f[p + 1] && m >= f[p]; ++p); --p;
	printf("%d ", p); res = calc(n, m, p); 
	if (f[p + 1] <= m) res += calc(m, m, p);
	printf("%d\n", res % mo);
}

int main() {
	gen();
	int T; 
	scanf("%d", &T);
	while (T--) solve(); 
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:44:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘LL {aka long long int}’ [-Wformat=]
   printf("1 %d\n", n % mo); return;
                          ^
./Main.cpp:38:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &m);
                           ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:56: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 209 ms 3328 KB
02.txt AC 208 ms 3328 KB
03.txt AC 209 ms 3328 KB
04.txt AC 208 ms 3328 KB
05.txt AC 208 ms 3328 KB
06.txt AC 209 ms 3328 KB
07.txt AC 211 ms 3328 KB
08.txt AC 208 ms 3328 KB
09.txt AC 209 ms 3328 KB
10.txt AC 209 ms 3328 KB
11.txt AC 362 ms 1920 KB
12.txt AC 362 ms 1920 KB
13.txt AC 163 ms 1920 KB
14.txt AC 163 ms 1920 KB
15.txt AC 168 ms 4096 KB
16.txt AC 168 ms 4096 KB
17.txt AC 133 ms 3840 KB
18.txt AC 134 ms 3840 KB
19.txt AC 341 ms 3584 KB
20.txt AC 340 ms 3584 KB
21.txt AC 1 ms 384 KB
22.txt AC 1 ms 384 KB
23.txt AC 1 ms 384 KB
24.txt AC 1 ms 384 KB
s1.txt AC 1 ms 384 KB
s2.txt AC 1 ms 384 KB