[NOIP2006] Series
★☆ input file: sequenc.in
output file: sequenc.out
Simple comparison
Time limit: 1 s memory limit: 162 MB
Title Description
Given a positive integer k (3≤k≤15), the operational of all k and all the finite cheqnered of the unequal k and constitute an ascending sequence, for example, when k=3, the sequence is:
1,3,4,9,ten ,.
(The sequence is actually:30,31,30+31,32,30+32,3 1+ 32,30+3 1+ 32 ,? )
Please find the value of the nth item of this sequence (denoted by a 10 decimal number).
For example, for k=3,n=100, the correct answer should be 981.
Input
Input file sequence.in only 1 lines, 2 positive integers, separated by a space:
K N (the meaning of K, n is consistent with the above problem description, and 3≤k≤15,10≤n≤1000).
Output
The output file, Sequence.out, is a positive integer (in all test data, the result is no more than 2.1x9). (Do not have spaces and other symbols before integers).
Sample input
3 100
Sample output
981
Find the law .... There's nothing to say ...
#include <cstdio>#include<cstring>using namespacestd;intK, N, CNT, f[1000000];intMain () {Freopen ("sequenc.in","R", stdin); Freopen ("Sequenc.out","W", stdout); scanf ("%d%d", &k, &N); CNT=1; f[1] =1; intnow =1; for(inti =1; ; ++i) { now*=K; intTN =CNT; for(intj =0; J <= TN; ++j) {f[++CNT] = F[j] +Now ; if(CNT >=N) {printf ("%d\n", F[n]); return 0; } } } return 0;}
"NOIP 2006" series