結果

問題 No.456 Millions of Submits!
ユーザー pekempeypekempey
提出日時 2016-12-08 08:21:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 4,500 ms
コード長 2,347 bytes
コンパイル時間 3,433 ms
コンパイル使用メモリ 181,516 KB
実行使用メモリ 5,204 KB
最終ジャッジ日時 2023-09-05 12:34:46
合計ジャッジ時間 11,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,836 KB
testcase_01 AC 5 ms
4,788 KB
testcase_02 AC 5 ms
4,736 KB
testcase_03 AC 4 ms
5,028 KB
testcase_04 AC 5 ms
4,852 KB
testcase_05 AC 5 ms
4,832 KB
testcase_06 AC 5 ms
4,916 KB
testcase_07 AC 5 ms
5,204 KB
testcase_08 AC 5 ms
4,760 KB
testcase_09 AC 8 ms
4,724 KB
testcase_10 AC 8 ms
4,912 KB
testcase_11 AC 36 ms
5,032 KB
testcase_12 AC 307 ms
4,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC optimize ("fast-math")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;

const int N = 1 << 17;
const double dx = log(10) / N;
const double ldx = log(log(10)) - 17 * log(2);
const double lte = -4 * log(10);

double lg[N + 1];
bool prime[N + 1];

namespace fastio {
    #define getchar getchar_unlocked
    #define putchar putchar_unlocked

    bool dot;

    int readInt() {
        int n, c;
        while ((c = getchar()) < '0') {
            assert(c != EOF);
        }
        n = c - '0';
        while ((c = getchar()) >= '0') {
            n = n * 10 + c - '0';
        }
        dot = c == '.';
        return n;
    }

    void printDouble(double x) {
        int a = x;
        int b = (x - a) * 1e9;
        int d[11];
        int i = 0;
        do {
            d[i++] = a % 10;
            a /= 10;
        } while (a > 0);
        while (i > 0) {
            putchar(d[--i] + '0');
        }
        putchar('.');
        while (i < 9) {
            d[i++] = b % 10;
            b /= 10;
        }
        while (i > 0) {
            putchar(d[--i] + '0');
        }
        putchar('\n');
    }
}

void sieve() {
    lg[0] = log(0);
    for (int i = 2; i <= N; i++) {
        if (!prime[i]) {
            double g = log(i);
            for (long long j = i; j <= N; j *= i) {
                for (int k = j; k <= N; k += j) {
                    prime[k] = true;
                    lg[k] += g;
                }
            }
        }
    }
    for (int i = 0; i <= N; i++) {
        lg[i] += ldx;
    }
}

double solve(int a, int b, int c, int d) {
    double lt = lg[c * 10000 + d] - ldx + lte;
    if (b == 0) {
        return exp(lt / a);
    }
    if (a == 0) {
        return exp(exp(lt / b));
    }
    int l = 0;
    int r = N;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        (a * mid * dx + b * lg[mid] >= lt ? r : l) = mid;
    }
    double s = (lg[r] - lg[l]) / dx;
    return exp((lt + s * b * l * dx - lg[l] * b) / (s * b + a));

}

int main() {
    sieve();
    int m = fastio::readInt();
    for (int i = 0; i < m; i++) {
        int a = fastio::readInt();
        int b = fastio::readInt();
        int c = fastio::readInt();
        int d = fastio::dot ? fastio::readInt() : 0;
        fastio::printDouble(solve(a, b, c, d));
    }
}
0