반응형

문제 출처 :


https://www.acmicpc.net/problem/7489



알고리즘 분석 :


문제 해결에 필요한 사항

1. 팩토리얼

2. 팩토리얼의 끝자리가 0일때의 의미



[1676번] 팩토리얼 0의 개수 :: http://www.crocus.co.kr/391 이 문제의 내용을 이용하고, 코드를 몇 줄만 추가해주면 정답이 도출된다.


이 문제 풀이에 대한 자세한 내용은 http://www.crocus.co.kr/391 에서 확인 할 수 있다.



[2553번] 마지막 팩토리얼 수 :: https://www.acmicpc.net/problem/2553 문제는 

7489번 문제에서 테스트 케이스만 빼면 코드가 동일하다. (문제 내용도 거의 같다.)





소스 코드 : 


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
#include <stdio.h>
 
int total = 1;
int cnt = 0;
 
int main()
{
    int n;
    int tCase;
    int i = 1;
    int tmp;
 
    scanf("%d"&tCase);
 
    while(tCase--)
    {
        scanf("%d"&n);
    
        while (n >= i)
        {
            total = total * i;
            i++;
 
            while (total % 10 == 0)
            {
                cnt++;
                total = total / 10;
            }
 
            if (total >= 100000)
            {
                tmp = total / 100000;
                tmp = tmp * 100000;
                total = total - tmp;
            }
        }
 
        printf("%d\n", total % 10);
        total = 1;
        i = 1;
    }
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus


반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[4883번] 삼각 그래프  (0) 2017.02.24
[1890번] 점프  (5) 2017.02.24
[1167번] 트리의 지름  (4) 2017.02.23
[4354번] 문자열 제곱  (1) 2017.02.23
[1305번] 광고  (0) 2017.02.22