結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー kapokapo
提出日時 2016-05-11 04:40:01
言語 C90
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,036 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 22,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 10:37:58
合計ジャッジ時間 1,238 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 0 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 0 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 0 ms
5,376 KB
testcase_28 AC 0 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 0 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:57:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
   57 |                 printf("%d\n", n);
      |                         ~^     ~
      |                          |     |
      |                          int   ll {aka long long int}
      |                         %lld
main.c:54:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |         scanf("%lld %lld %lld %lld", &n, &a, &b, &c);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

typedef long long ll;

ll calc(ll x, ll y)
{
	if( y == 0 ) return x;
	return calc( y, x%y );
}

ll calc2(ll x, ll y)
{
	ll z = calc( y, x%y );
	return (x/z) * (y/z) * z;
}

ll calc3(ll x, ll y, ll z)
{
	int i, c=1, cnt=1;
	while( cnt ) {
		cnt=0;
		for( i = 2; i <= x; i++) {
			if( !(x%i) && !(y%i) && !(z%i) ) {
				c *= i;
				x /= i; y /= i; z /= i;
				cnt++;
			}
		}
	}
	for( i = 2; i <= x; i++) {
		if( !(x%i) && !(y%i) ) {
			c *= i;
			x /= i; y /= i;
		}
	}
	for( i = 2; i <= x; i++) {
		if( !(x%i) && !(z%i) ) {
			c *= i;
			x /= i; z /= i;
		}
	}
	for( i = 2; i <= y; i++) {
		if( !(y%i) && !(z%i) ) {
			c *= i;
			y /= i; z /= i;
		}
	}
	return c*x*y*z;
}

int main(void)
{
	ll i, n, a, b, c, ab, bc, ac, abc, cnt=0;
	scanf("%lld %lld %lld %lld", &n, &a, &b, &c);

	if( a == 1 || b == 1 || c == 1 ){
		printf("%d\n", n);
		return 0;
	}

	ab = calc2(b, a);
	bc = calc2(c, b);
	ac = calc2(c, a);

	abc = calc3(a, b, c);

	printf("%lld\n", (n/a)+(n/b)+(n/c)-(n/ab)-(n/bc)-(n/ac)+(n/abc) );

	return 0;
}
0