시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB129450543441.932%

문제

n!은 정수 n에 대한 팩토리얼 수를 나타내는데, 이는 1부터 n까지의 모든 정수의 곱을 의미한다. 팩토리얼은 굉장히 빨리 커지기 때문에 13!는 대부분의 컴퓨터에서 32비트 정수형을, 70!은 대부분의 부동 소수점 변수의 범위를 넘어선다. 우리는 n!에 대하여 0이 아닌 최우측 수(the rightmost non-zero digit)를 찾으려고 한다. 예를 들어, 5! = 1 * 2 * 3 * 4 * 5 = 120 이므로 5!의 최우측 0이 아닌 수는 2이다. 마찬가지로 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040이며 7!의 0이 아닌 최우측 수는 4가 된다.

입력

첫 줄에 테스트 케이스의 수 t ( 0 < t < 15)가 주어진다. 연속하여 t개의 줄에는 정수 n이 하나씩 주어진다. ( 0 < n < 1001).

출력

n!의 최우측 0이 아닌 수(the rightmost non-zero digit)를 출력하시오.

예제 입력 1

1
5

예제 출력 1

2

힌트

비슷한 문제로 https://www.acmicpc.net/problem/2553가 있다.

W3sicHJvYmxlbV9pZCI6Ijc0ODkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzMjlcdWQxYTBcdWI5YWNcdWM1YmMiLCJkZXNjcmlwdGlvbiI6IjxwPm4hXHVjNzQwIFx1YzgxNVx1YzIxOCBuXHVjNWQwIFx1YjMwMFx1ZDU1YyBcdWQzMjlcdWQxYTBcdWI5YWNcdWM1YmMgXHVjMjE4XHViOTdjIFx1YjA5OFx1ZDBjMFx1YjBiNFx1YjI5NFx1YjM3MCwgXHVjNzc0XHViMjk0IDFcdWJkODBcdWQxMzAgblx1YWU0Y1x1YzljMFx1Yzc1OCBcdWJhYThcdWI0ZTAgXHVjODE1XHVjMjE4XHVjNzU4IFx1YWNmMVx1Yzc0NCBcdWM3NThcdWJiZjhcdWQ1NWNcdWIyZTQuIFx1ZDMyOVx1ZDFhMFx1YjlhY1x1YzViY1x1Yzc0MC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0d2VlbiAxIGFuZCAxMDAwIGluY2x1c2l2ZS4mbmJzcDs8XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD5QcmludCB0byB0aGUgb3V0cHV0IHRoZSByaWdodG1vc3Qgbm9uLXplcm8gZGlnaXQgb2YgbiEmbmJzcDs8XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwiaHRtbF90aXRsZSI6IjAiLCJwcm9ibGVtX2xhbmdfdGNvZGUiOiJFbmdsaXNoIn1d

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > All-Ukrainian Collegiate Programming Contest > AUCPC Semi-Final 2010 I번