結果

問題 No.415 ぴょん
ユーザー suppy193suppy193
提出日時 2016-11-17 13:54:29
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 978 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 24,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 20:30:51
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 0 ms
4,380 KB
testcase_26 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘lcm’:
main.c:16:16: warning: passing argument 1 of ‘swap’ makes pointer from integer without a cast [-Wint-conversion]
  if(m < n)swap(m, n);
                ^
main.c:4:26: note: expected ‘long long int *’ but argument is of type ‘long long int’
 void swap(long long int *a, long long int *b)
           ~~~~~~~~~~~~~~~^
main.c:16:19: warning: passing argument 2 of ‘swap’ makes pointer from integer without a cast [-Wint-conversion]
  if(m < n)swap(m, n);
                   ^
main.c:4:44: note: expected ‘long long int *’ but argument is of type ‘long long int’
 void swap(long long int *a, long long int *b)
                             ~~~~~~~~~~~~~~~^

ソースコード

diff #

#include <stdio.h>
#include <string.h>

void swap(long long int *a, long long int *b)
{
	long long int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

int lcm(long long int m, long long int n)
{
	long long int temp;
	
	if(m < n)swap(m, n);
	while(n != 0){
		temp = n;
		n = m % n;
		m = temp;
	}

	return m;
}


int main(void) {
	int i;
	int pos;
	int foot[20] = {0};
	long long int n, d;
	int cnt;
	
	/*
	for(n = 1;n < 10;n++){
		for(d = 1;d <= n;d++){
			printf("n = %lld, d = %lld : ", n, d);
			memset(foot, (int)0, sizeof(foot));
			pos = 1;
			cnt = 0;
			while(foot[pos] != 1){
				printf("%d ", pos);
				foot[pos] = 1;
				cnt++;
				pos = (pos - 1 + d) % n + 1;
			}
			
			printf(" %d times\n", cnt - 1);
		}
		printf("\n");
	}
	*/	
	//lcm(8, 6);
	
	scanf("%lld%lld", &n, &d);
	if(n == d)printf("0\n");
	else if(d == 1 || n - 1 == d)printf("%lld\n", n - 1);
	else if(lcm(n, d) == 1)printf("%lld\n", n - 1);
	else {
		printf("%lld\n", n / lcm(n, d) - 1);
	}
	
	return 0;
}
0