Submission #1372552


Source Code Expand

#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cassert>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int t,tot,ans;
LL n,m,f[100][2];

LL getLL()
{
    char ch;
    while (!isdigit(ch=getchar()));
    LL x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void dfs(LL x,LL y,int k)
{
    if (!k)
    {
        ans=(ans+(m-x-y)/y+1)%p;
        if (n>=x+y)
            ans=(ans+(n-x-y)/y+1)%p;
        return;
    }
    for (LL z=x+y*((!x)+1); z<=m; z+=y)
    {
        //assert(y*f[k][0]+z*f[k][1]>0 && y*f[k-1][0]+z*f[k-1][1]>0);
        if (y*f[k][0]+z*f[k][1]>m || y*f[k-1][0]+z*f[k-1][1]>n)
            break;
        if (z!=x+y*((!x)+1) && k>1)
            dfs(y*f[k-2][0]+z*f[k-2][1],y*f[k-1][0]+z*f[k-1][1],0);
        else
            dfs(y,z,k-1);
    }
}

void solve()
{
    n=getLL(),m=getLL();
    if (n>m)
        swap(n,m);
    for (tot=0; f[tot][1]<=n && f[tot+1][1]<=m; ++tot);
    if (--tot<=1)
    {
        printf("1 %d\n",n%p*m%p);
        return;
    }
    ans=0,dfs(0,1,tot-1);
    printf("%d %d\n",tot,ans);
}

int main()
{
    f[0][1]=f[1][0]=f[1][1]=1;
    repu(i,2,90)
        f[i][0]=f[i-1][0]+f[i-2][0],f[i][1]=f[i-1][1]+f[i-2][1];
    for (scanf("%d",&t); t--; solve());
    return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:51:32: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘LL {aka long long int}’ [-Wformat=]
         printf("1 %d\n",n%p*m%p);
                                ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:63:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for (scanf("%d",&t); t--; solve());
                        ^

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 284 ms 3072 KB
02.txt AC 287 ms 3072 KB
03.txt AC 283 ms 3072 KB
04.txt AC 283 ms 3072 KB
05.txt AC 284 ms 3072 KB
06.txt AC 284 ms 3072 KB
07.txt AC 284 ms 3072 KB
08.txt AC 285 ms 3200 KB
09.txt AC 284 ms 3072 KB
10.txt AC 284 ms 3072 KB
11.txt AC 493 ms 1792 KB
12.txt AC 493 ms 1792 KB
13.txt AC 155 ms 1792 KB
14.txt AC 157 ms 1792 KB
15.txt AC 198 ms 3968 KB
16.txt AC 199 ms 3968 KB
17.txt AC 102 ms 3584 KB
18.txt AC 102 ms 3584 KB
19.txt AC 606 ms 3456 KB
20.txt AC 610 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