結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー zimphazimpha
提出日時 2017-03-29 22:34:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 800 ms
コード長 4,069 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 75,624 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-09-20 20:21:07
合計ジャッジ時間 18,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
56,424 KB
testcase_01 AC 110 ms
55,460 KB
testcase_02 AC 113 ms
56,208 KB
testcase_03 AC 42 ms
49,404 KB
testcase_04 AC 111 ms
55,660 KB
testcase_05 AC 112 ms
55,392 KB
testcase_06 AC 112 ms
55,960 KB
testcase_07 AC 110 ms
55,436 KB
testcase_08 AC 43 ms
49,824 KB
testcase_09 AC 113 ms
55,864 KB
testcase_10 AC 112 ms
55,976 KB
testcase_11 AC 112 ms
55,956 KB
testcase_12 AC 113 ms
56,016 KB
testcase_13 AC 111 ms
55,672 KB
testcase_14 AC 111 ms
55,688 KB
testcase_15 AC 109 ms
55,848 KB
testcase_16 AC 107 ms
55,460 KB
testcase_17 AC 110 ms
56,176 KB
testcase_18 AC 112 ms
55,864 KB
testcase_19 AC 104 ms
55,872 KB
testcase_20 AC 109 ms
55,908 KB
testcase_21 AC 113 ms
55,852 KB
testcase_22 AC 109 ms
55,960 KB
testcase_23 AC 113 ms
55,452 KB
testcase_24 AC 113 ms
55,988 KB
testcase_25 AC 109 ms
55,692 KB
testcase_26 AC 106 ms
55,704 KB
testcase_27 AC 111 ms
55,592 KB
testcase_28 AC 110 ms
55,960 KB
testcase_29 AC 108 ms
55,424 KB
testcase_30 AC 113 ms
55,544 KB
testcase_31 AC 114 ms
55,956 KB
testcase_32 AC 111 ms
55,964 KB
testcase_33 AC 112 ms
55,792 KB
testcase_34 AC 108 ms
55,488 KB
testcase_35 AC 109 ms
55,432 KB
testcase_36 AC 111 ms
55,964 KB
testcase_37 AC 111 ms
56,068 KB
testcase_38 AC 109 ms
55,432 KB
testcase_39 AC 110 ms
55,960 KB
testcase_40 AC 109 ms
55,900 KB
testcase_41 AC 109 ms
55,944 KB
testcase_42 AC 109 ms
55,928 KB
testcase_43 AC 107 ms
55,972 KB
testcase_44 AC 109 ms
55,752 KB
testcase_45 AC 109 ms
56,012 KB
testcase_46 AC 108 ms
55,952 KB
testcase_47 AC 108 ms
56,016 KB
testcase_48 AC 109 ms
56,060 KB
testcase_49 AC 110 ms
55,900 KB
testcase_50 AC 111 ms
55,844 KB
testcase_51 AC 110 ms
55,660 KB
testcase_52 AC 108 ms
55,548 KB
testcase_53 AC 108 ms
55,804 KB
testcase_54 AC 109 ms
55,852 KB
testcase_55 AC 107 ms
55,640 KB
testcase_56 AC 106 ms
55,528 KB
testcase_57 AC 109 ms
55,552 KB
testcase_58 AC 109 ms
53,448 KB
testcase_59 AC 111 ms
55,448 KB
testcase_60 AC 110 ms
55,500 KB
testcase_61 AC 107 ms
56,060 KB
testcase_62 AC 107 ms
55,604 KB
testcase_63 AC 110 ms
56,032 KB
testcase_64 AC 108 ms
55,844 KB
testcase_65 AC 107 ms
55,708 KB
testcase_66 AC 110 ms
54,260 KB
testcase_67 AC 108 ms
56,064 KB
testcase_68 AC 111 ms
55,756 KB
testcase_69 AC 110 ms
56,132 KB
testcase_70 AC 109 ms
55,456 KB
testcase_71 AC 108 ms
55,372 KB
testcase_72 AC 111 ms
56,168 KB
testcase_73 AC 110 ms
56,028 KB
testcase_74 AC 113 ms
55,960 KB
testcase_75 AC 113 ms
55,440 KB
testcase_76 AC 112 ms
55,968 KB
testcase_77 AC 108 ms
56,276 KB
testcase_78 AC 110 ms
55,724 KB
testcase_79 AC 111 ms
55,784 KB
testcase_80 AC 109 ms
55,988 KB
testcase_81 AC 109 ms
55,876 KB
testcase_82 AC 107 ms
55,952 KB
testcase_83 AC 110 ms
55,984 KB
testcase_84 AC 110 ms
55,916 KB
testcase_85 AC 111 ms
55,920 KB
testcase_86 AC 109 ms
55,912 KB
testcase_87 AC 109 ms
55,756 KB
testcase_88 AC 112 ms
56,168 KB
testcase_89 AC 110 ms
55,900 KB
testcase_90 AC 111 ms
55,972 KB
testcase_91 AC 108 ms
55,500 KB
testcase_92 AC 111 ms
56,000 KB
testcase_93 AC 110 ms
55,960 KB
testcase_94 AC 111 ms
55,704 KB
testcase_95 AC 107 ms
55,748 KB
testcase_96 AC 111 ms
55,172 KB
testcase_97 AC 113 ms
55,736 KB
testcase_98 AC 110 ms
55,876 KB
testcase_99 AC 111 ms
56,144 KB
testcase_100 AC 110 ms
55,440 KB
testcase_101 AC 110 ms
55,880 KB
testcase_102 AC 110 ms
55,592 KB
testcase_103 AC 111 ms
55,812 KB
testcase_104 AC 109 ms
55,368 KB
testcase_105 AC 111 ms
55,728 KB
testcase_106 AC 111 ms
55,736 KB
testcase_107 AC 114 ms
55,996 KB
testcase_108 AC 115 ms
55,908 KB
testcase_109 AC 110 ms
55,712 KB
testcase_110 AC 113 ms
55,972 KB
testcase_111 AC 112 ms
55,716 KB
testcase_112 AC 114 ms
56,272 KB
testcase_113 AC 110 ms
55,440 KB
testcase_114 AC 110 ms
56,044 KB
testcase_115 AC 110 ms
55,372 KB
testcase_116 AC 109 ms
55,736 KB
testcase_117 AC 112 ms
55,608 KB
testcase_118 AC 110 ms
55,704 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