結果

問題 No.415 ぴょん
コンテスト
ユーザー suppy193
提出日時 2016-11-17 13:54:29
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 978 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 162 ms
コンパイル使用メモリ 38,100 KB
最終ジャッジ日時 2026-02-23 22:53:55
ジャッジサーバーID
(参考情報)
judge1 / judge1
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'lcm':
main.c:16:23: warning: passing argument 1 of 'swap' makes pointer from integer without a cast [-Wint-conversion]
   16 |         if(m < n)swap(m, n);
      |                       ^
      |                       |
      |                       long long int
main.c:16:23: note: possible fix: take the address with '&'
   16 |         if(m < n)swap(m, n);
      |                       ^
      |                       &
main.c:4:26: note: expected 'long long int *' but argument is of type 'long long int'
    4 | void swap(long long int *a, long long int *b)
      |           ~~~~~~~~~~~~~~~^
main.c:16:26: warning: passing argument 2 of 'swap' makes pointer from integer without a cast [-Wint-conversion]
   16 |         if(m < n)swap(m, n);
      |                          ^
      |                          |
      |                          long long int
main.c:16:26: note: possible fix: take the address with '&'
   16 |         if(m < n)swap(m, n);
      |                          ^
      |                          &
main.c:4:44: note: expected 'long long int *' but argument is of type 'long long int'
    4 | void swap(long long int *a, long long int *b)
      |                             ~~~~~~~~~~~~~~~^

ソースコード

diff #
raw source code

#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