Submission #1402415
Source Code Expand
/*
srt: 2017年07月04日 15時22分28秒
鹧鸪天·晚日寒鸦一片愁 辛弃疾
晚日寒鸦一片愁。柳塘新绿却温柔。若教眼底无离恨,不信人间有白头。
肠已断,泪难收。相思重上小红楼。情知已被山遮断,频倚阑干不自由。
end: 2017年07月04日 16時39分11秒
*/
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int mod=1e9+7;
ll f[100];int n;
// 1,2,3,5,8
// x,y,x+y,x+2y,2x+3y,3x+5y,5x+8y
void forward(ll x,ll y,int i,ll&c,ll lima,ll limb)
{
ll a,b;
if(i<2)
{
if(i==0)a=x,b=y;
else a=y,b=x+y;
if(a>lima||b>limb)return;
}else{
if(lima/x<f[i-2]||lima/y<f[i-1]||x*f[i-2]>lima-y*f[i-1])return;
if(limb/x<f[i-1]||limb/y<f[ i ]||x*f[i-1]>limb-y*f[ i ])return;
a=x*f[i-2]+y*f[i-1];
b=x*f[i-1]+y*f[i];
}
(c+=(limb-b)/a+1)%=mod;
if(b<=lima)
(c+=(lima-b)/a+1)%=mod;
}
void work(ll x,ll y)
{
int i,k=std::upper_bound(f+1,f+n,x)-f-1;
if(f[k+1]>y)k=std::upper_bound(f+1,f+n,y)-f-2;
ll c=((y-f[k+1])/f[k]+1)%mod;
if(f[k+1]<=x)
(c+=(x-f[k+1])/f[k]+1)%=mod;
for(i=1;i<k;i++)
{
forward(f[i],2*f[i]+f[i-1],k-i,c,x,y);
forward(f[i],3*f[i]+f[i-1],k-i,c,x,y);
}
printf("%d %lld\n",k,c);
}
int main()
{
ll x,y;int i;
f[0]=f[1]=1;
for(n=1;f[n]>0;n++)
f[n+1]=f[n]+f[n-1];
scanf("%d",&i);
while(i--)
{
scanf("%lld%lld\n",&x,&y);
if(x==1||y==1||(x==2&&y==2))
printf("1 %lld\n",x*y%mod);
else
x>y&&(x^=y^=x^=y),work(x,y);
}
}
Submission Info
Submission Time
2017-07-04 17:46:59+0900
Task
F - Kenus the Ancient Greek
User
htn
Language
C++14 (GCC 5.4.1)
Score
1700
Code Size
1504 Byte
Status
AC
Exec Time
1545 ms
Memory
3968 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:58:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&i);
^
./Main.cpp:61:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld\n",&x,&y);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1700 / 1700
Status
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
663 ms
3072 KB
02.txt
AC
662 ms
3072 KB
03.txt
AC
661 ms
3072 KB
04.txt
AC
662 ms
3072 KB
05.txt
AC
663 ms
3072 KB
06.txt
AC
662 ms
3072 KB
07.txt
AC
662 ms
3072 KB
08.txt
AC
661 ms
3072 KB
09.txt
AC
661 ms
3072 KB
10.txt
AC
663 ms
3072 KB
11.txt
AC
1545 ms
1792 KB
12.txt
AC
1543 ms
1792 KB
13.txt
AC
406 ms
1792 KB
14.txt
AC
408 ms
1792 KB
15.txt
AC
421 ms
3968 KB
16.txt
AC
421 ms
3968 KB
17.txt
AC
129 ms
3584 KB
18.txt
AC
129 ms
3584 KB
19.txt
AC
1300 ms
3456 KB
20.txt
AC
1304 ms
3456 KB
21.txt
AC
1 ms
128 KB
22.txt
AC
1 ms
128 KB
23.txt
AC
1 ms
128 KB
24.txt
AC
1 ms
128 KB
s1.txt
AC
1 ms
128 KB
s2.txt
AC
1 ms
128 KB