結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー zimphazimpha
提出日時 2017-03-29 22:28:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,100 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 79,272 KB
実行使用メモリ 54,204 KB
最終ジャッジ日時 2024-07-06 15:11:23
合計ジャッジ時間 14,069 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
53,916 KB
testcase_01 AC 96 ms
52,936 KB
testcase_02 AC 116 ms
53,812 KB
testcase_03 AC 47 ms
50,148 KB
testcase_04 AC 105 ms
53,828 KB
testcase_05 AC 109 ms
54,044 KB
testcase_06 AC 105 ms
54,112 KB
testcase_07 AC 106 ms
54,000 KB
testcase_08 AC 49 ms
50,476 KB
testcase_09 AC 109 ms
54,128 KB
testcase_10 AC 95 ms
52,940 KB
testcase_11 AC 111 ms
53,828 KB
testcase_12 AC 97 ms
52,656 KB
testcase_13 AC 95 ms
52,816 KB
testcase_14 AC 106 ms
53,944 KB
testcase_15 AC 96 ms
52,940 KB
testcase_16 AC 95 ms
52,852 KB
testcase_17 AC 96 ms
52,884 KB
testcase_18 AC 111 ms
53,736 KB
testcase_19 AC 99 ms
52,912 KB
testcase_20 AC 113 ms
54,196 KB
testcase_21 AC 102 ms
53,964 KB
testcase_22 AC 99 ms
53,624 KB
testcase_23 AC 107 ms
54,008 KB
testcase_24 AC 103 ms
53,868 KB
testcase_25 AC 108 ms
53,924 KB
testcase_26 AC 108 ms
53,916 KB
testcase_27 AC 116 ms
53,848 KB
testcase_28 AC 112 ms
54,204 KB
testcase_29 AC 97 ms
52,872 KB
testcase_30 AC 94 ms
52,884 KB
testcase_31 AC 94 ms
52,612 KB
testcase_32 AC 96 ms
52,928 KB
testcase_33 AC 106 ms
53,724 KB
testcase_34 AC 98 ms
53,204 KB
testcase_35 AC 105 ms
54,104 KB
testcase_36 AC 98 ms
52,916 KB
testcase_37 AC 99 ms
52,688 KB
testcase_38 AC 109 ms
53,844 KB
testcase_39 AC 106 ms
54,092 KB
testcase_40 AC 94 ms
52,856 KB
testcase_41 AC 105 ms
54,152 KB
testcase_42 AC 105 ms
53,084 KB
testcase_43 AC 103 ms
52,736 KB
testcase_44 AC 119 ms
53,964 KB
testcase_45 AC 105 ms
52,832 KB
testcase_46 AC 107 ms
54,012 KB
testcase_47 AC 95 ms
52,868 KB
testcase_48 AC 120 ms
54,100 KB
testcase_49 AC 117 ms
54,012 KB
testcase_50 AC 106 ms
53,972 KB
testcase_51 AC 108 ms
53,900 KB
testcase_52 AC 98 ms
52,940 KB
testcase_53 AC 109 ms
53,952 KB
testcase_54 AC 117 ms
53,976 KB
testcase_55 AC 107 ms
54,040 KB
testcase_56 AC 109 ms
54,068 KB
testcase_57 AC 108 ms
54,116 KB
testcase_58 AC 118 ms
54,088 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 RE -
testcase_111 RE -
testcase_112 RE -
testcase_113 RE -
testcase_114 RE -
testcase_115 AC 99 ms
52,696 KB
testcase_116 AC 110 ms
53,996 KB
testcase_117 AC 105 ms
53,832 KB
testcase_118 AC 108 ms
53,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task493 solver = new Task493();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task493 {
        long[] sum;
        long[] prod;
        int[] len;
        String[] digits;
        static final int mod = 1000000000 + 7;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int K = in.nextInt();
            long L = in.nextLong();
            long R = in.nextLong();

            sum = new long[100];
            prod = new long[100];
            len = new int[100];
            digits = new String[100];

            sum[0] = 0;
            prod[0] = 1;
            len[0] = 0;
            int m = 0;
            for (int i = 1; i <= K; ++i) {
                digits[i] = new Integer(i * i).toString();
                len[i] = len[i - 1] * 2 + digits[i].length();
                sum[i] = sum[i - 1] * 2 % mod;
                prod[i] = prod[i - 1] * prod[i - 1] % mod;
                for (char c : digits[i].toCharArray()) {
                    int d = c - '0';
                    if (d == 0) d = 10;
                    sum[i] = (sum[i] + d) % mod;
                    prod[i] = prod[i] * d % mod;
                }
                m = i;
                if (len[i] >= R) break;
            }
            if (len[m] < R) {
                out.println(-1);
                return;
            }
            long[] A = calc(R, m);
            long[] B = calc(L - 1, m);
            long x = (A[0] - B[0] + mod) % mod;
            long y = A[1] * MathUtils.pow_mod(B[1], mod - 2, mod) % mod;
            out.printf("%d %d\n", x, y);
        }

        long[] calc(long n, int m) {
            if (n <= 0) {
                return new long[]{0, 1};
            }
            if (len[m - 1] >= n) {
                return calc(n, m - 1);
            }
            long x = sum[m - 1];
            long y = prod[m - 1];
            for (int i = 0; i < digits[m].length() && i + 1 + len[m - 1] <= n; ++i) {
                int d = digits[m].charAt(i) - '0';
                if (d == 0) d = 10;
                x = (x + d) % mod;
                y = y * d % mod;
            }
            long[] t = calc(n - len[m - 1] - digits[m].length(), m - 1);
            return new long[]{(x + t[0]) % mod, y * t[1] % mod};
        }

    }

    static class MathUtils {
        public static long pow_mod(long a, long n, long mod) {
            long result = 1;
            for (; n >= 1; n >>= 1) {
                if (n % 2 == 1) result = result * a % mod;
                a = a * a % mod;
            }
            return result;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

0