Submission #1320585


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) | rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int Mod = 1e9 + 7;

LL n, m;

int Min_step;

pair<pair<LL, LL>, pair<LL, LL> > coe[100];

int ans;

void dfs(LL x, LL y, int res)
{
	if (!res)
	{
		(ans += ((m - y) / x + 1) % Mod) %= Mod;
		if (y <= n && x != y) (++ans) %= Mod;
		return;
	}
	swap(y, x);
	--res;
	while (1)
	{
		y += x;
		if (y > m) break;
		if (y >= 2 * x && y > n) break;
		if (x * coe[res].x.x + y * coe[res].x.y > n) break;
		if (x * coe[res].y.x + y * coe[res].y.y > m) break;
		dfs(x, y, res);
	}
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	coe[0] = mp(mp(1LL, 0LL), mp(0LL, 1LL));
	REP(i, 1, 100)
	{
		coe[i] = coe[i - 1];
		swap(coe[i].x, coe[i].y);
		coe[i].y.x += coe[i].x.x;
		coe[i].y.y += coe[i].x.y;
	}
	int case_cnt;
	scanf("%d", &case_cnt);
	for (int case_id = 1; case_id <= case_cnt; ++case_id)
	{
		scanf("%" LLFORMAT "d%" LLFORMAT "d", &n, &m);
		if (n > m) swap(n, m);
		ans = 0;
		Min_step = 1;
		while (coe[Min_step + 1].x.x + coe[Min_step + 1].x.y <= n && coe[Min_step + 1].y.x + coe[Min_step + 1].y.y <= m) ++Min_step;
		if (Min_step == 1) ans = (LL)(n % Mod) * (m % Mod) % Mod;
		else dfs(1, 1, Min_step);
		(ans += Mod) %= Mod;
		printf("%d %d\n", Min_step, ans);
	}
	return 0;
}

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User matthew99
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 2026 Byte
Status AC
Exec Time 3273 ms
Memory 3968 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:75:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &case_cnt);
                        ^
./Main.cpp:78:48: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%" LLFORMAT "d%" LLFORMAT "d", &n, &m);
                                                ^

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 922 ms 3200 KB
02.txt AC 920 ms 3200 KB
03.txt AC 917 ms 3200 KB
04.txt AC 919 ms 3200 KB
05.txt AC 922 ms 3200 KB
06.txt AC 919 ms 3200 KB
07.txt AC 918 ms 3200 KB
08.txt AC 916 ms 3200 KB
09.txt AC 918 ms 3200 KB
10.txt AC 923 ms 3200 KB
11.txt AC 1772 ms 1920 KB
12.txt AC 1761 ms 1920 KB
13.txt AC 246 ms 1792 KB
14.txt AC 246 ms 1792 KB
15.txt AC 286 ms 3968 KB
16.txt AC 283 ms 3968 KB
17.txt AC 127 ms 3712 KB
18.txt AC 127 ms 3712 KB
19.txt AC 3273 ms 3584 KB
20.txt AC 3101 ms 3456 KB
21.txt AC 1 ms 256 KB
22.txt AC 1 ms 256 KB
23.txt AC 1 ms 256 KB
24.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB