ITRIX12E - R Numbers
R - Numbers
R-numbers are numbers which have the property that they do not have the digit '0' and sum of every two adjacent digits of the number is prime. 123 is a R-number because 1+2 =3 and 2+3 =5 and 3, 5 are primes.
How many R-numbers can be formed with at most length N?
i.e. R-numbers of length 1 + R-numbers of length 2 + R-numbers of length 3 + ... R-numbers of length N.
Length of a number = Number of digits in the number.
Only four single digit numbers are R-numbers which are nothing but single digit primes 2, 3, 5, 7.
Input Specification
The first line of the input file contains T which denotes the number of test cases. The next T lines contain an integer N <= 10^9.
Output Specification
Print the numbers of R-numbers modulo 1000000007. [10^9+7];
Example
Sample Input: 2 1 2 Sample Output: 4 33
hide comments
yazan_kh44:
2024-11-14 20:35:18
@ harshit2202
|
|
ranjith13:
2023-06-23 06:33:16
Can someone help me why its giving run time and what is better optimisation for this solution
|
|
smso:
2021-07-20 13:30:31
Used G.P. sum with common ratio in the form of matrix. |
|
harshit2202:
2019-03-16 08:41:34
I can find it for particular N in log N
|
|
shahianshu:
2018-10-07 09:41:51
Amazing problem , solved using linear recurrence relation :) |
|
masterchef2209:
2018-09-08 14:40:48
ONE HELL OF A QUESTION |
|
arnauddesombre:
2018-08-23 17:36:48
(correct) answers for a few values of n:
|
|
narutorocks:
2016-06-03 09:16:25
NICE QUESTION LEARNT A LOT |
|
harkirat:
2016-05-15 08:59:27
@david : wrong |
|
David:
2013-09-24 20:17:39
Sorry - my bad and WA at the time.
|
Added by: | Radhakrishnan Venkataramani |
Date: | 2012-03-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own problem |