Recent Posts
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Today
Total
관리 메뉴

Try

[Programmers/C++] Ugly Number 구하기 본문

Algorithm/Programmers

[Programmers/C++] Ugly Number 구하기

HAS3ONG 2018. 11. 12. 00:42

출처

https://uva.onlinejudge.org/external/1/p136.pdf


코딩도장

http://codingdojang.com/




Ugly numbers are numbers whose only prime factors are 2, 3 or 5






소스


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
/*    
/*    khsh5592@naver.com
/*    has3ong.tistory.com
/*    
/*    2018 - 11 - 12
/*
*/
 
#include<iostream>
#include<conio.h>
 
using namespace std;
 
 
int Ugly_Number(int n)
{
    if(n==1)
    {
        return 1;
    }
    else if(n % 2 == 0)
    {
        n = n/2;
    }
    else if(n % 3 == 0)
    {
        n = n/3;
    }
    else if(n % 5 == 0)
    {
        n = n/5;
    }
    else
    {
        return 0;
    }
 
    Ugly_Number(n);
}
 
void main()
{        
    int count;
    cin >> count;
    int n = 1;
    
    while(count < 500)
    {
        n++;
        if (Ugly_Number(n) == 1)
        {
            count++;
        }
    }
    cout << "The ugly number is " << n << endl;
    getch();
}
cs


Comments