結果

問題 No.500 階乗電卓
ユーザー ohreitetsuohreitetsu
提出日時 2018-05-28 22:53:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 63,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 20:16:10
合計ジャッジ時間 1,453 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string.h>
using namespace std;
typedef long long LL;
LL MAX=999999999999;
int main(int argc, char* argv[])
{
	LL N;
	cin>>N;
	int i;

	LL v=1;
	for (i=2;i<=N;i++){
		v=v*i;
		if (v>MAX){
			char p[100];
			sprintf(p,"%lld",v);
			char *p1=p+strlen(p)-12;
			char *p2=p1;
			bool allZero=true;
			while (*p2!='\0'){
				if (*p2!='0'){
					allZero=false;
					break;
				}
				p2++;
			}
			if (allZero==true){
				cout<<"000000000000"<<endl;
				return 0;
			}
			if (i<N){
				sscanf(p1,"%lld",&v);
			}else{
				cout<<p1<<endl;
				return 0;
			}
		}
	}
	cout<<v<<endl;
	return 0;
}
0