UV 443-Humble Numbers

Source: Internet
Author: User

Question: Calculate the nth number in the number set consisting of {2, 3, 5, 7.

Analysis: Four pointers are used to correspond to the current corresponding factor of each number. The minimum value is obtained each time and the pointer is moved back. Pay attention to equal conditions.

Note: The output count.

[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
 
Int d [5850];
Int v [4] = {2, 3, 5, 7 };
Int p [4] = {1, 1, 1 };
 
Int main ()
{Www.2cto.com
Int count = 2; d [1] = 1;
While (count <= 5842 ){
Int min = 2000000001;
For (int I = 0; I <4; ++ I)
If (min> v [I] * d [p [I])
Min = v [I] * d [p [I];
For (int I = 0; I <4; ++ I)
If (min = v [I] * d [p [I])
P [I] ++;
D [count ++] = min;
}
Int n;
While (scanf ("% d", & n ){
Printf ("The % d", n );
If (n % 100 = 11 | n % 100 = 12 | n % 100 = 13)
Printf ("th ");
Else if (n % 10 = 1)
Printf ("st ");
Else if (n % 10 = 2)
Printf ("nd ");
Else if (n % 10 = 3)
Printf ("rd ");
Else printf ("th ");
Printf ("humble number is % d. \ n", d [n]);
}
Return 0;
}

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.