Test instructions
The qualitative factor of a number is only a few of the 2,3,5,7. This is called humble number.
For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ...
Give N and ask the nth humble number.
Ideas:
The construction of all humble numbers is: (2^a) * (3^b) * (5^c) * (7^d). A,b,c,d is greater than or equal to 0.
X=a+b+c+d represents the number of x humble.
Assuming that the first i-1 humble number has been calculated, the first I humble how to ask?
Must be one of the humble in the first i-1 humble number multiplied by 2 or multiplied by 3 or multiplied by 5 or multiplied by 7.
Well, before enumerating the i-1 humble number, finding the number of i-1 humble and the smallest, then it is the number I humble.
Look at the code
Code:
ll a[5850];intcn=0;intMain () {a[1]=1; CN=1; while(cn<5842) {ll ans=INF; ll temp; Rep (I,1, CN) {Temp=a[i]*2;if(TEMP>A[CN]) ans=min (ans,temp); Temp=a[i]*3;if(TEMP>A[CN]) ans=min (ans,temp); Temp=a[i]*5;if(TEMP>A[CN]) ans=min (ans,temp); Temp=a[i]*7;if(TEMP>A[CN]) ans=min (ans,temp); } a[++cn]=ans; } intN; while(SCANF ("%d",&N), N) {intt=n%Ten; if(t==1&& n% -!= One) {printf ("The %dst humble number is", N); } Else if(t==2&& n% -!= A) {printf ("The %dnd humble number is", N); } Else if(t==3&& n% -!= -) {printf ("The %DRD humble number is", N); } Else{printf ("The %dth humble number is", N); } printf ("%i64d.\n", A[n]); } return 0;}
HDU 1058 Humble Numbers (construction?) Enumeration? )