Submission #1321599


Source Code Expand

// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MOD = 1e9 + 7;

LL X, Y;
vector<pair<LL, LL>> fib;

inline pair<LL, LL> operator+ (const pair<LL, LL> &a, const pair<LL, LL> &b)
{
    return MP(a.x + b.x, a.y + b.y);
}

void prework()
{
    fib.push_back(MP(1, 0));
    fib.push_back(MP(0, 1));
    while (fib.back().y <= 1e18) {
        fib.push_back(MP(fib[SZ(fib)-2].x + fib.back().x, fib[SZ(fib)-2].y + fib.back().y));
    }
}

int ans, cnt;

void calc(LL x, LL y, int len)
{
    if (x > X || y > Y)
        return;
    if (len == ans) {
        (cnt += ((Y - y) / x + 1) % MOD) %= MOD;
        return;
    }
    int d = ans - len;
    for (;;) {
        LL t1 = x * fib[d].x + y * fib[d].y;
        LL t2 = x * fib[d+1].x + y * fib[d+1].y;
        if (t1 > X || t2 > Y)
            break;
        calc(y, x + y, len + 1);
        y += x;
    }
}

void solve()
{
    if (X > Y)
        std::swap(X, Y);

    for (int i = 0; fib[i].x + fib[i].y <= X; ++i) {
        if (fib[i+1].x + fib[i+1].y <= Y)
            ans = i;
    }
    if (ans <= 1) {
        printf("1 %lld\n", X * Y % MOD);
        return;
    }

    cnt = 0;
    calc(1, 2, 1);
    std::swap(X, Y);
    calc(1, 2, 1);

    printf("%d %d\n", ans, cnt);
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    prework();
    int Q;
    read(Q);
    while (Q--) {
        read(X); read(Y);
        solve();
    }

    return 0;
}

// 彻头彻尾的反Unix系统,就是让进程的生成代价高昂,让进程的控制
// 困难而死板,让IPC可有可无,对它不予支持或支持很少。
//     -- 《UNIX编程艺术》by ESR

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User Ivlleiooq
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 3795 Byte
Status AC
Exec Time 3452 ms
Memory 3968 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 984 ms 3200 KB
02.txt AC 982 ms 3200 KB
03.txt AC 976 ms 3200 KB
04.txt AC 976 ms 3200 KB
05.txt AC 980 ms 3200 KB
06.txt AC 982 ms 3200 KB
07.txt AC 987 ms 3200 KB
08.txt AC 969 ms 3200 KB
09.txt AC 979 ms 3200 KB
10.txt AC 984 ms 3200 KB
11.txt AC 1983 ms 1920 KB
12.txt AC 1964 ms 1920 KB
13.txt AC 229 ms 1792 KB
14.txt AC 228 ms 1792 KB
15.txt AC 242 ms 3968 KB
16.txt AC 243 ms 3968 KB
17.txt AC 72 ms 3712 KB
18.txt AC 74 ms 3712 KB
19.txt AC 3452 ms 3456 KB
20.txt AC 3419 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