Submission #1333863


Source Code Expand

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int N = 233;
typedef long long LL;
typedef pair <LL,LL> pr;
const LL mo = 1000000007;
const LL Max = 1E18 + 233LL;

int q,tp;
LL f[N];

#define fr first
#define sc second
#define mp(a,b) (make_pair((a),(b)))

vector <pr> v[N];

inline LL getLL()
{
	char ch = getchar(); LL ret = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9')
		ret = ret * 10LL + 1LL * (ch - '0'),ch = getchar();
	return ret;
}

inline void Solve(LL x,LL y)
{
	if (x == 1)
	{
		printf("1 %d\n",y % mo); return;
	}
	else if (x == 2 && y == 2) {puts("1 4"); return;}
	int Ans = 0; LL cnt = 0;
	for (int i = 1; ; i++)
		if (f[i] > x || f[i + 1] > y) {Ans = i - 1; break;}
	for (int i = 0; i < v[Ans - 1].size(); i++)
	{
		pr now = v[Ans - 1][i];
		if (now.fr <= x)
			cnt += (y - now.sc) / now.fr;
		if (now.fr <= y)
			cnt += (x - now.sc) / now.fr;
		cnt %= mo;
	}
	printf("%d %d\n",Ans,cnt % mo);
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	f[0] = f[1] = 1;
	for (int i = 2; ; i++)
	{
		f[i] = f[i - 1] + f[i - 2];
		if (f[i] > Max) {tp = i; break;}
	}
	v[1].push_back(mp(2,1)); v[1].push_back(mp(3,1));
	for (int i = 2; i < tp - 1; i++)
		for (int j = 0; j < v[i - 1].size(); j++)
		{
			pr now = v[i - 1][j];
			for (LL k = 1; ; k++)
			{
				pr nex = mp(now.fr * k + now.sc,now.fr);
				if (nex.fr > f[i + 2] || nex.sc > f[i + 2]) break; v[i].push_back(nex);
			}
		}
	q = getLL();
	while (q--)
	{
		LL x = getLL(),y = getLL();
		if (x > y) swap(x,y); Solve(x,y);
	}
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘void Solve(LL, LL)’:
./Main.cpp:43:25: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘LL {aka long long int}’ [-Wformat=]
   printf("1 %d\n",y % mo); return;
                         ^
./Main.cpp:58:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘LL {aka long long int}’ [-Wformat=]
  printf("%d %d\n",Ans,cnt % mo);
                               ^

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 267 ms 3328 KB
02.txt AC 266 ms 3328 KB
03.txt AC 264 ms 3328 KB
04.txt AC 266 ms 3328 KB
05.txt AC 265 ms 3328 KB
06.txt AC 264 ms 3328 KB
07.txt AC 266 ms 3328 KB
08.txt AC 266 ms 3328 KB
09.txt AC 264 ms 3328 KB
10.txt AC 267 ms 3328 KB
11.txt AC 540 ms 1920 KB
12.txt AC 539 ms 1920 KB
13.txt AC 167 ms 1920 KB
14.txt AC 165 ms 1920 KB
15.txt AC 200 ms 4096 KB
16.txt AC 199 ms 4096 KB
17.txt AC 108 ms 3840 KB
18.txt AC 108 ms 3840 KB
19.txt AC 461 ms 3584 KB
20.txt AC 464 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