No.493 Long Long Sequence and a String
レベル :
/ AI推定難易度 : 1500
/ 実行時間制限 : 1ケース 0.800秒 / メモリ制限
: 256 MB / 標準ジャッジ問題
タグ : / 解いたユーザー数 42
作問者 :
e869120
/ テスター :
square1001
タグ : / 解いたユーザー数 42
作問者 :
e869120
/ テスター :
問題文最終更新日: 2026-06-25 01:23:27
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 158
(順位表)
の他の問題:
Problem Statement
Consider the following sequences.f(1)={1}
f(2)={1,4,1}
f(3)={1,4,1,9,1,4,1}
f(n)=f(n-1) + $n^2$ + f(n-1)
Consider concatenating such a sequence into a string.
For example, f(3) becomes "1419141", and if the sequence were {9,11,10}, it would become "91110".
You are given K, L, and R.
Find the sum and the product of the digits from the L-th character to the R-th character of the string obtained from f(K).
Only the product should be reported as the remainder when divided by $1000000007$($10^9+7$).
However, if a 0 is included, the product would normally become 0, which is not interesting, so the digit "0" is treated as "10", only when calculating the sum and the product.
If the value of R exceeds the number of characters in the string obtained from f(K), output "-1".
Here are some examples.
Example 1: If f(K) is "91110" and L=2, R=5, the sum is $1+1+1+10=13$ and the product is $1*1*1*10=10$.
Example 2: If f(K) is "1419141" and L=1,R=7, the sum is $1+4+1+9+1+4+1=21$ and the product is $1*4*1*9*1*4*1=144$.
Example 3: If f(K) is "7777777" and L=4,R=5, the sum is $7+7=14$ and the product is $7*7=49$.
Incidentally, the relevant part is "1110" in Example 1, "1419141" in Example 2, and "77" in Example 3.
For reference, the strings obtained from f(1) through f(5) are as follows.
String obtained from f(1) ⇒ "1"
String obtained from f(2) ⇒ "141"
String obtained from f(3) ⇒ "1419141"
String obtained from f(4) ⇒ "1419141161419141"
String obtained from f(5) ⇒ "1419141161419141251419141161419141"
Input
K L R
・1≦K≦10^9
・1≦L≦R≦10^18
Output
On one line, output the sum of the digits from the L-th character to the R-th character of the string obtained from f(K), and the remainder of their product when divided by 1000000007, separated by a space.
Here, L and R are 1-indexed.
Sample
Sample 1
Input
3 1 7
Output
21 144
This is already explained in the examples in the problem statement.
Sample 2
Input
5 12 19
Output
24 360
The string from the 12th to the 19th character is "19141251", so the sum is 24 and the product is 360.
Sample 3
Input
10 510 515
Output
17 96
Sample 4
Input
10 1 2016
Output
-1
The string made from the sequence f(10) has a length of 1151 characters, so there is no 2016th character.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。