結果

問題 No.442 和と積
ユーザー tj_0612tj_0612
提出日時 2016-11-18 02:43:41
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 727 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 21,120 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-04 15:18:15
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:23:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%llu %llu",&A,&B);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

unsigned long long int gcd(unsigned long long int a,unsigned long long int b){
	unsigned long long int temp,r;
	while(1){
		if(a>b){
			temp=a;
			a=b;
			b=temp;
		}
		else{
			r=b%a;
			if(r==0)
				break;
			b=r;
		}
	}
	return a;
}

int main(){
	unsigned long long int A,B;
	scanf("%llu %llu",&A,&B);

	unsigned long long int a,gcd_ab,gcd_aa,eq_gcd,calc;
	a=A+B;

	gcd_aa=gcd(a,A);
	gcd_ab=gcd(a,B);
	eq_gcd=gcd(gcd_ab,gcd_aa);

	calc = gcd_ab*gcd_aa/eq_gcd;
	unsigned long long int i=1;
	while(1){
		if(calc>=a){
			calc /=i-1;
			break;
		}
		else if(i>eq_gcd)
			break;
		if(gcd(i,eq_gcd)==i && gcd(calc*i,a)==calc*i){
			calc *= i;
			eq_gcd/=i;
		}
		i++;
	}



	printf("%llu\n",calc);
	return 0;
}
0