Submission #1372800


Source Code Expand

#include <iostream>

#include <cstdio>

#include <vector>

#include <cstring>

#include <cstdlib>

#include <cassert>

#include <iostream>

#define rep(i,a,b) for(int i = a; i <= b; i++)

#define dep(i,a,b) for(int i = a; i >= b; i--)

#define Rep(i,a) for(int i = 0; i < a; i++)

#define pb push_back

#define mp make_pair

typedef long long LL;

using namespace std;

const int N = 90, mod = 1e9 + 7;
typedef pair<LL, LL> pii;
LL f[N];
int cnt = 0;
vector<pii> g[N];
void dfs(int t, LL a, LL b) {
	if (a > 2LL * f[t] || b > LL(1e18)) return;
	if (f[t] <= a && a < f[t + 2] && f[t + 1] <= b && b < f[t + 2]) g[t].pb(mp(a, b));
	rep(i,1,4) dfs(t + 1, b, a + b * i);
}

LL read() {
	char c = getchar(); LL x = 0;
	while (c < '0' || c > '9') c = getchar();
	while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}


int main() {

//	freopen("gcd.in","r",stdin);

//	freopen("gcd.out","w",stdout);

	f[0] = f[1] = 1; rep(i,2,87) f[i] = f[i - 1] + f[i - 2];
	dfs(0, 1, 1);
	int Q; scanf("%d",&Q);
	while (Q--) {
		LL a, b; a = read(), b = read();
		if (a > b) swap(a, b); int mx = 1;
		dep(i,86,1) if (f[i] <= a && f[i + 1] <= b) { mx = i; break; }
		if (mx == 1) printf("%d %d\n",mx, 1LL * a * b % mod);
		else {
			int len = g[mx].size(); int ans = 0;
			Rep(j,len) {
				LL x = g[mx][j].first, y = g[mx][j].second;
				if (x <= a && y <= b) ans++;
				if (y <= a && x <= b) ans++;
			}
			len = g[mx - 1].size();
			Rep(j,len) {
				LL x = g[mx - 1][j].first, y = g[mx - 1][j].second;
				if (y <= a && b >= f[mx + 2]) 
					ans = (ans + (b - x) / y - (f[mx + 2] - 1 - x) / y) % mod;
			}
			if (ans < 0) ans += mod;
			printf("%d %d\n",mx, ans);
		}
	}
	return 0;

}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:61:54: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘LL {aka long long int}’ [-Wformat=]
   if (mx == 1) printf("%d %d\n",mx, 1LL * a * b % mod);
                                                      ^
./Main.cpp:56:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int Q; scanf("%d",&Q);
                       ^

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 226 ms 3328 KB
03.txt AC 225 ms 3328 KB
04.txt AC 226 ms 3328 KB
05.txt AC 226 ms 3328 KB
06.txt AC 226 ms 3328 KB
07.txt AC 226 ms 3328 KB
08.txt AC 225 ms 3328 KB
09.txt AC 226 ms 3328 KB
10.txt AC 230 ms 3328 KB
11.txt AC 287 ms 1920 KB
12.txt AC 283 ms 1920 KB
13.txt AC 129 ms 1920 KB
14.txt AC 128 ms 1920 KB
15.txt AC 176 ms 4096 KB
16.txt AC 177 ms 4096 KB
17.txt AC 122 ms 3840 KB
18.txt AC 122 ms 3840 KB
19.txt AC 466 ms 3584 KB
20.txt AC 466 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