結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー zimphazimpha
提出日時 2017-03-29 22:28:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,100 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 75,684 KB
実行使用メモリ 56,344 KB
最終ジャッジ日時 2023-09-20 20:20:45
合計ジャッジ時間 14,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
56,220 KB
testcase_01 AC 111 ms
55,212 KB
testcase_02 AC 110 ms
55,836 KB
testcase_03 AC 42 ms
49,564 KB
testcase_04 AC 112 ms
55,952 KB
testcase_05 AC 111 ms
53,572 KB
testcase_06 AC 111 ms
55,580 KB
testcase_07 AC 111 ms
56,096 KB
testcase_08 AC 42 ms
50,008 KB
testcase_09 AC 111 ms
55,552 KB
testcase_10 AC 111 ms
56,220 KB
testcase_11 AC 111 ms
55,728 KB
testcase_12 AC 111 ms
55,568 KB
testcase_13 AC 111 ms
56,128 KB
testcase_14 AC 113 ms
55,280 KB
testcase_15 AC 108 ms
56,052 KB
testcase_16 AC 111 ms
55,684 KB
testcase_17 AC 110 ms
55,756 KB
testcase_18 AC 108 ms
56,108 KB
testcase_19 AC 107 ms
55,924 KB
testcase_20 AC 110 ms
56,256 KB
testcase_21 AC 108 ms
55,952 KB
testcase_22 AC 109 ms
56,072 KB
testcase_23 AC 110 ms
56,272 KB
testcase_24 AC 107 ms
55,940 KB
testcase_25 AC 110 ms
56,036 KB
testcase_26 AC 110 ms
56,344 KB
testcase_27 AC 111 ms
55,788 KB
testcase_28 AC 111 ms
56,096 KB
testcase_29 AC 109 ms
56,136 KB
testcase_30 AC 108 ms
56,272 KB
testcase_31 AC 110 ms
56,160 KB
testcase_32 AC 110 ms
55,812 KB
testcase_33 AC 111 ms
55,760 KB
testcase_34 AC 109 ms
55,948 KB
testcase_35 AC 109 ms
55,632 KB
testcase_36 AC 110 ms
55,612 KB
testcase_37 AC 111 ms
56,052 KB
testcase_38 AC 110 ms
56,088 KB
testcase_39 AC 108 ms
55,536 KB
testcase_40 AC 111 ms
55,996 KB
testcase_41 AC 110 ms
56,020 KB
testcase_42 AC 112 ms
53,992 KB
testcase_43 AC 108 ms
55,696 KB
testcase_44 AC 110 ms
55,996 KB
testcase_45 AC 111 ms
56,136 KB
testcase_46 AC 112 ms
55,744 KB
testcase_47 AC 111 ms
55,720 KB
testcase_48 AC 110 ms
55,748 KB
testcase_49 AC 110 ms
56,272 KB
testcase_50 AC 110 ms
55,896 KB
testcase_51 AC 111 ms
55,852 KB
testcase_52 AC 108 ms
55,808 KB
testcase_53 AC 109 ms
56,192 KB
testcase_54 AC 110 ms
55,484 KB
testcase_55 AC 113 ms
55,920 KB
testcase_56 AC 112 ms
55,732 KB
testcase_57 AC 110 ms
56,072 KB
testcase_58 AC 110 ms
55,628 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 110 ms
55,892 KB
testcase_116 AC 108 ms
56,116 KB
testcase_117 AC 110 ms
55,816 KB
testcase_118 AC 112 ms
55,840 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