結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
54,092 KB
testcase_01 AC 96 ms
52,972 KB
testcase_02 AC 94 ms
52,952 KB
testcase_03 AC 47 ms
50,376 KB
testcase_04 AC 95 ms
52,724 KB
testcase_05 AC 104 ms
53,784 KB
testcase_06 AC 112 ms
54,016 KB
testcase_07 AC 110 ms
54,084 KB
testcase_08 AC 48 ms
50,492 KB
testcase_09 AC 100 ms
53,424 KB
testcase_10 AC 109 ms
54,112 KB
testcase_11 AC 107 ms
53,964 KB
testcase_12 AC 109 ms
53,744 KB
testcase_13 AC 92 ms
52,664 KB
testcase_14 AC 108 ms
54,000 KB
testcase_15 AC 114 ms
54,144 KB
testcase_16 AC 112 ms
53,940 KB
testcase_17 AC 104 ms
53,300 KB
testcase_18 AC 111 ms
53,964 KB
testcase_19 AC 112 ms
53,924 KB
testcase_20 AC 112 ms
54,096 KB
testcase_21 AC 112 ms
54,108 KB
testcase_22 AC 115 ms
53,796 KB
testcase_23 AC 121 ms
53,872 KB
testcase_24 AC 109 ms
54,004 KB
testcase_25 AC 107 ms
54,036 KB
testcase_26 AC 114 ms
54,064 KB
testcase_27 AC 120 ms
53,712 KB
testcase_28 AC 110 ms
54,168 KB
testcase_29 AC 115 ms
53,968 KB
testcase_30 AC 112 ms
53,852 KB
testcase_31 AC 101 ms
53,232 KB
testcase_32 AC 102 ms
52,716 KB
testcase_33 AC 112 ms
53,996 KB
testcase_34 AC 109 ms
53,792 KB
testcase_35 AC 105 ms
53,968 KB
testcase_36 AC 106 ms
53,864 KB
testcase_37 AC 110 ms
54,104 KB
testcase_38 AC 97 ms
52,964 KB
testcase_39 AC 111 ms
54,032 KB
testcase_40 AC 108 ms
53,836 KB
testcase_41 AC 98 ms
52,976 KB
testcase_42 AC 118 ms
54,020 KB
testcase_43 AC 103 ms
52,916 KB
testcase_44 AC 109 ms
53,960 KB
testcase_45 AC 96 ms
52,932 KB
testcase_46 AC 105 ms
54,004 KB
testcase_47 AC 116 ms
53,932 KB
testcase_48 AC 113 ms
54,132 KB
testcase_49 AC 102 ms
53,032 KB
testcase_50 AC 109 ms
54,140 KB
testcase_51 AC 104 ms
53,976 KB
testcase_52 AC 107 ms
54,072 KB
testcase_53 AC 110 ms
54,004 KB
testcase_54 AC 108 ms
53,988 KB
testcase_55 AC 114 ms
53,820 KB
testcase_56 AC 107 ms
54,228 KB
testcase_57 AC 95 ms
53,024 KB
testcase_58 AC 101 ms
53,752 KB
testcase_59 AC 107 ms
53,688 KB
testcase_60 AC 107 ms
53,756 KB
testcase_61 AC 108 ms
53,852 KB
testcase_62 AC 97 ms
52,656 KB
testcase_63 AC 110 ms
53,888 KB
testcase_64 AC 111 ms
53,912 KB
testcase_65 AC 96 ms
52,928 KB
testcase_66 AC 97 ms
52,716 KB
testcase_67 AC 115 ms
53,716 KB
testcase_68 AC 111 ms
54,040 KB
testcase_69 AC 106 ms
53,836 KB
testcase_70 AC 99 ms
52,952 KB
testcase_71 AC 114 ms
53,996 KB
testcase_72 AC 109 ms
54,088 KB
testcase_73 AC 103 ms
54,000 KB
testcase_74 AC 115 ms
53,908 KB
testcase_75 AC 107 ms
54,224 KB
testcase_76 AC 108 ms
53,940 KB
testcase_77 AC 108 ms
54,004 KB
testcase_78 AC 103 ms
52,728 KB
testcase_79 AC 108 ms
53,856 KB
testcase_80 AC 109 ms
54,056 KB
testcase_81 AC 111 ms
54,192 KB
testcase_82 AC 102 ms
53,440 KB
testcase_83 AC 97 ms
52,860 KB
testcase_84 AC 95 ms
52,992 KB
testcase_85 AC 104 ms
52,944 KB
testcase_86 AC 114 ms
53,960 KB
testcase_87 AC 108 ms
53,980 KB
testcase_88 AC 115 ms
53,888 KB
testcase_89 AC 105 ms
53,864 KB
testcase_90 AC 102 ms
53,712 KB
testcase_91 AC 108 ms
54,136 KB
testcase_92 AC 110 ms
54,104 KB
testcase_93 AC 109 ms
54,004 KB
testcase_94 AC 108 ms
53,788 KB
testcase_95 AC 105 ms
54,088 KB
testcase_96 AC 108 ms
53,960 KB
testcase_97 AC 99 ms
53,376 KB
testcase_98 AC 110 ms
54,176 KB
testcase_99 AC 115 ms
53,772 KB
testcase_100 AC 115 ms
53,944 KB
testcase_101 AC 106 ms
54,136 KB
testcase_102 AC 99 ms
53,584 KB
testcase_103 AC 97 ms
52,964 KB
testcase_104 AC 99 ms
52,940 KB
testcase_105 AC 108 ms
54,112 KB
testcase_106 AC 108 ms
53,988 KB
testcase_107 AC 108 ms
54,008 KB
testcase_108 AC 109 ms
54,120 KB
testcase_109 AC 118 ms
53,848 KB
testcase_110 AC 105 ms
53,968 KB
testcase_111 AC 111 ms
53,876 KB
testcase_112 AC 110 ms
53,928 KB
testcase_113 AC 109 ms
54,128 KB
testcase_114 AC 105 ms
54,000 KB
testcase_115 AC 114 ms
54,032 KB
testcase_116 AC 108 ms
54,104 KB
testcase_117 AC 107 ms
53,912 KB
testcase_118 AC 115 ms
53,940 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;
        long[] 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 long[100];
            digits = new String[100];

            sum[0] = 0;
            prod[0] = 1;
            len[0] = 0;
            int m = 0;
            for (int i = 1; i <= K && i < 100; ++i) {
                digits[i] = new Integer(i * i).toString();
                len[i] = len[i - 1] * 2 + digits[i].length();
                sum[i] = sum[i - 1] * 2;
                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;
                    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];
            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;
                y = y * d % mod;
            }
            long[] t = calc(n - len[m - 1] - digits[m].length(), m - 1);
            return new long[]{x + t[0], 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