Submission #1372567


Source Code Expand

#include<cstdio>
#include<algorithm>
#define ll long long
#define MN 500
using namespace std;
ll read_p,read_ca,read_f;
inline ll read(){
	read_p=0;read_ca=getchar();read_f=1;
	while (read_ca<'0'||read_ca>'9') read_f=read_ca=='-'?-1:read_f,read_ca=getchar();
	while (read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
	return read_p*read_f;
}
int T;
const ll M=1e18;
const int MOD=1e9+7;
struct na{ll x,y;}S[MN][MN];
ll n,m,F[MN],mmh,MMH;
int main(){
	T=read();
	F[0]=F[1]=1;
	for (ll i=2;(F[i]=F[i-1]+F[i-2])<=M;i++);
	S[0][0].x=S[0][0].y=1;
	for (ll i=1;F[i]<=M;i++){
		for (ll j=0;j<i;j++) S[i][j].x=S[i-1][j].x+S[i-1][j].y,S[i][j].y=S[i-1][j].x;
		S[i][i].x=F[i+2];S[i][i].y=F[i];
	}
	while(T--){
		n=read();m=read();
		if (n==1&&m==1) {printf("1 1\n");continue;}
		if (n<m) swap(n,m);
		mmh=1;
		while (F[mmh+2]<=n&&F[mmh+1]<=m) mmh++;
		printf("%lld ",mmh);mmh--;
		MMH=0;
		for (ll i=0;i<=mmh;i++){
			if (m>=S[mmh][i].x) (MMH+=(n-S[mmh][i].y)/S[mmh][i].x)%=MOD;
			if (n>=S[mmh][i].x) (MMH+=(m-S[mmh][i].y)/S[mmh][i].x)%=MOD;
		}
		printf("%lld\n",(MMH+(mmh?0:m))%MOD);
	}
}

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User swm_sxt
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 1148 Byte
Status AC
Exec Time 574 ms
Memory 4352 KB

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 292 ms 3584 KB
02.txt AC 291 ms 3584 KB
03.txt AC 291 ms 3584 KB
04.txt AC 291 ms 3584 KB
05.txt AC 291 ms 3584 KB
06.txt AC 291 ms 3584 KB
07.txt AC 292 ms 3584 KB
08.txt AC 294 ms 3584 KB
09.txt AC 291 ms 3584 KB
10.txt AC 292 ms 3584 KB
11.txt AC 574 ms 2176 KB
12.txt AC 574 ms 2176 KB
13.txt AC 185 ms 2176 KB
14.txt AC 184 ms 2176 KB
15.txt AC 218 ms 4352 KB
16.txt AC 219 ms 4352 KB
17.txt AC 125 ms 4096 KB
18.txt AC 120 ms 4096 KB
19.txt AC 498 ms 3840 KB
20.txt AC 501 ms 3968 KB
21.txt AC 1 ms 512 KB
22.txt AC 1 ms 512 KB
23.txt AC 1 ms 512 KB
24.txt AC 1 ms 512 KB
s1.txt AC 1 ms 512 KB
s2.txt AC 1 ms 512 KB