반응형
<코드>
#include<iostream>
#include<algorithm>
using namespace std;
int n, t, ans;
int main()
{
cin >> t;
while (t--)
{
cin >> n;
ans = 1;
for (int i = 1; i <= n; i++)
{
ans *= i;
ans %= 100000;
while (ans % 10 == 0)
ans /= 10;
}
cout << ans % 10 << '\n';
}
}
비슷한 문제
[C/C++] 백준 2553번 -마지막 팩토리얼 수
<코드> #include #include using namespace std; long long n, ans; int main() { cin >> n; ans = 1; for (int i = 1; i <= n; i++) { ans *= i; ans %= 10000000; // 1천만 while (ans % 10 == 0) ans /= 10; }..
cocoon1787.tistory.com
7489번: 팩토리얼
n!은 정수 n에 대한 팩토리얼 수를 나타내는데, 이는 1부터 n까지의 모든 정수의 곱을 의미한다. 팩토리얼은 굉장히 빨리 커지기 때문에 13!는 대부분의 컴퓨터에서 32비트 정수형을, 70!은 대부분
www.acmicpc.net
반응형
'🧩PS > 🥈Nomal' 카테고리의 다른 글
[C/C++] 백준 1074번 - Z (분할정복) (0) | 2021.01.17 |
---|---|
[C/C++] 백준 17946번 - 피자는 나눌 수록 커지잖아요 (0) | 2021.01.17 |
[C/C++] 백준 2553번 -마지막 팩토리얼 수 (0) | 2021.01.17 |
[C/C++] 백준 2810번 - 컵홀더 (0) | 2021.01.16 |
[Python] 백준 14928번 - 큰 수 (BIG) (0) | 2021.01.15 |