Hamming Number:
m=1^i+2^j+5^k,按此规律,m=1,2,3,4,5,6,8,9,……,求第n个m
01 #include <iostream>
02 using namespace std;
03 04 void main(){
05 int n,i;
06 long CountHum = 1, num = 2;
07 i = num;
08 09 10 cout<<
"Enter the N you want:"<<endl;
11 cin>>n;
12 13 14 if (n == 1)
15 cout<<
"The Nth number is:1"<<endl;
16 else {
17 while (CountHum < n){
18 while (1){
19 if (i % 2 == 0)
20 i = i/2;
21 if (i % 3 == 0)
22 i = i/3;
23 if (i % 5 == 0)
24 i = i/5;
25 if (i == 1)
26 break;
27 else28 if (!((i % 2 == 0) || (i % 3 == 0) || (i % 5 == 0)))
29 break;
30 }
31 32 33 if (i == 1)
34 CountHum++;
35 num++;
36 i = num;
37 }
38 39 40 cout<<
"The Nth number is:"<<num-1<<endl;
41 }
42 }