"NOIP 2006" series

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.