Codevs 3943 Math Wizards Kiki

Source: Internet
Author: User

"Title Description Description "

As an excellent disciple of the Kamishirasawa teacher, mathematical Wizards Kiki Cirno has deep attainments in arithmetic. Today, Codevs was fortunate to have invited this wonderful mathematical field as the first examiner of the exam.

Kiki Cirno like the number between 0-9, she likes to the decimal non-negative number of each bit one by one to identify, and then add them together with a calculator, that is, the number of digits of the sum, for example, for 1234, Kiki will use a calculator to calculate the 1+2+3+4=10.

Kiki Cirno not only uses the addition of calculators, but also uses the subtraction, multiplication, and exponentiation of the calculator, and she thinks that a number x is interesting to her, and when she calculates the sum of the digits of x, it takes the operation of the power of the K, then multiply P , plus or minus |q| , the resulting number is exactly x.

Gigi Cirno is very curious to find out how many X are interesting to her in all the integers x within a range [l,r], and she wants you to help her solve the problem.

Enter a description Input Description

The first line is three integers k,p and q, which means to seek the power of K, multiplied by P, if q is regular plus |q|, if the non-regular minus |q|.

The second row of two non-negative integers l and r, indicates the desired interval, guaranteeing l≤r.

Output description Output Description

The first line is a non-negative integer n, which indicates how many interesting x.

If n is positive, the second row outputs n non-negative integers in ascending order, representing the n interesting numbers, separated by a space between the numbers, with extra spaces at the end of the line.

Sample input Sample Input

2 2-1

1 999

Sample output Sample Output

4

1 31 337 967

Data range and Tips Data Size & Hint

For 100% of the data, there is 1≤k≤5,0≤p,|q|≤10000,0≤l≤r≤109.

"Problem-solving ideas"

This is the first question of the Codevs, many people complain that the input data to the wrong, the largest to 10^10, but I was not affected, because this topic is not a violent enumeration to do, it is clear that the maximum number is 999999999, when the sum of all the digits is 81, That is to say that there is not a number of everyone plus and 81, then we just need to enumerate the 81 number of processed values, and determine whether the value is within range.

1  ProgramShuxue;2 varK,p,q,l,r,i,j,sum,n:longint;3B:Array[1.. -] ofInt64;4 C:int64;5 begin6 read (k,p,q);7 read (l,r);8      fori:=1  to Bayi  Doa[i]:=i;9      fori:=1  to Bayi  DoTen     begin One          forj:=1  toK-1  Do Aa[i]:=a[i]*i; -a[i]:=a[i]*p; -a[i]:=a[i]+Q; the     End; -      fori:=1  to Bayi  Do -     begin -sum:=0; +         if(a[i]>=l) and(A[I]<=R) Then -         begin +c:=A[i]; A              whileA[i]>0  Do at             begin -Sum:=a[i]MoD Ten+sum; -A[i]:=a[i]Div Ten; -             End; -             ifSum=i Then -             begin in Inc (n); -b[n]:=C; to             End; +         End; -     End; the writeln (n); *      fori:=1  toN DoWrite (B[i],' '); $ End.Panax Notoginseng 

Codevs 3943 Math Wizards Kiki

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.