結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー sasa
提出日時 2025-03-18 16:11:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 28,416 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-18 16:11:04
合計ジャッジ時間 1,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other AC * 14 WA * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long int*’ [-Wformat=]
   20 |         scanf("%d",&val);
      |                ~^  ~~~~
      |                 |  |
      |                 |  long int*
      |                 int*
      |                %ld
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d",&val);
      |         ~~~~~^~~~~~~~~~~
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%d%d%d",&A, &B, &C);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

// 最大公約数を求める関数
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

// 最小公倍数を求める関数
int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
}

int main(void){
	long val = 0;
	scanf("%d",&val);
	
	int A, B, C;
	scanf("%d%d%d",&A, &B, &C);
	
	long ans = 0;
	
	ans += val / A;
	ans += val / B;
	ans += val / C;
	ans -= val / lcm(A,B);
	ans -= val / lcm(B,C);
	ans -= val / lcm(C,A);
	ans -= val / lcm(lcm(C,A),B);
	
	printf("%ld",ans);
}
0