Submission #2672003


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
int read() {
    int x; scanf("%lld", &x); return x;
}
#define xx first
#define yy second
#define pb push_back
typedef pair<int, int> pir;
const int mod = 1000000007;

vector<pir> f, s[100];
int fib[100];
int find(int a, int b) {
	int ka = upper_bound(fib + 1, fib + 91, a) - fib;
	int kb = upper_bound(fib + 1, fib + 91, b) - fib;
	if (ka > kb + 1) ka = kb + 1;
	if (ka == kb) kb--;
	return kb - 1;
}

signed main() {
    f.pb(pir(1, 1));
    f.pb(pir(3, 2));
    f.pb(pir(4, 3));
    s[2].pb(pir(3, 2));
    for (int i = 3; i <= 90; i++) {
        f.pb(pir(f[i - 1].xx + f[i - 2].xx, f[i - 1].yy + f[i - 2].yy));
        for (int j = 0; j < i - 2; j++) {
            s[i].push_back(pir(s[i - 1][j].xx + s[i - 1][j].yy, s[i - 1][j].xx));
        }
        s[i].pb(pir(f[i - 1].xx + f[i - 1].yy, f[i - 1].xx));
    }
    fib[0] = fib[1] = 1;
    for (int i = 2; i <= 90; i++)
    	fib[i] = fib[i - 1] + fib[i - 2];
    	
    int Q = read();
    while (Q--) {
    	int A = read(), B = read(), ans = 0;
		if (A < B) swap(A, B);
		if (B == 1) { printf("1 %lld\n", A % mod); continue; }
		if (A == 2 && B == 2) { puts("1 4"); continue; }
    	int k = find(A, B);
    	printf("%lld ", k);
    	for (int i = 0, _ = s[k].size(); i < _; i++) {
    		int x = s[k][i].xx, y = s[k][i].yy;
    		if (y <= B && x <= A) {
    			ans = (ans + (A - x) / y + 1) % mod;
    		}
    		if (y <= A && x <= B) {
    			ans = (ans + (B - x) / y + 1) % mod;
    		}
    	}
    	if (f[k].xx <= A && f[k].yy <= B)
    		ans = (ans + 1) % mod;
    	if (f[k].xx <= B && f[k].yy <= A)
    		ans = (ans + 1) % mod;
    	printf("%lld\n", ans);
    }
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘long long int read()’:
./Main.cpp:5:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int x; scanf("%lld", &x); return x;
                             ^

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 219 ms 3328 KB
02.txt AC 219 ms 3328 KB
03.txt AC 218 ms 3328 KB
04.txt AC 218 ms 3328 KB
05.txt AC 219 ms 3328 KB
06.txt AC 219 ms 3328 KB
07.txt AC 219 ms 3328 KB
08.txt AC 218 ms 3328 KB
09.txt AC 219 ms 3328 KB
10.txt AC 219 ms 3328 KB
11.txt AC 279 ms 1920 KB
12.txt AC 278 ms 1920 KB
13.txt AC 156 ms 1920 KB
14.txt AC 155 ms 1920 KB
15.txt AC 185 ms 4096 KB
16.txt AC 185 ms 4096 KB
17.txt AC 149 ms 3840 KB
18.txt AC 149 ms 3840 KB
19.txt AC 355 ms 3584 KB
20.txt AC 355 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