結果

問題 No.1200 お菓子配り-3
ユーザー fura
提出日時 2020-09-09 17:30:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,012 ms / 4,000 ms
コード長 504 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 193,204 KB
最終ジャッジ日時 2025-01-14 08:54:45
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int x,y; scanf("%d%d",&x,&y);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:31:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

void solve(){
	int x,y; scanf("%d%d",&x,&y);

	int ans=0;
	for(int d=1;d*d<=x+y;d++) if((x+y)%d==0) {
		for(lint a:{d-1,(x+y)/d-1}) if(a>=2) {
			lint D=a*a-1;
			lint b=a*x-y,c=-x+a*y;
			if(b%D==0 && c%D==0){
				b/=D;
				c/=D;
				if(b>0 && c>0) ans++;
			}
		}
	}

	// a == 1
	if(x==y) ans+=x-1;

	printf("%d\n",ans);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0