結果

問題 No.1200 お菓子配り-3
ユーザー KKT89
提出日時 2020-08-28 21:54:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 845 bytes
コンパイル時間 1,230 ms
コンパイル使用メモリ 94,648 KB
最終ジャッジ日時 2025-01-13 17:15:32
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>
using namespace std;
typedef long long int ll;

ll X,Y;

ll count_res(ll i,ll j){
    if(j<2)return 0;
    ll a=i-1;
    if(a==1){
        if(X-j!=0||Y-j!=0)return 0;
        return j-2;
    }
    else{
        if((X-j)%(a-1))return 0;
        if((Y-j)%(a-1))return 0;
        ll b=(X-j)/(a-1);
        ll c=(Y-j)/(a-1);
        return b>=1&&c>=1&&b+c==j;
    }
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while(q--){
        cin >> X >> Y;
        int x=X+Y;
        ll res=0;
        for(int i=2;i*i<=x;i++){
            if(x%i==0){
                res+=count_res(i,x/i);
                if(x/i!=i)res+=count_res(x/i,i);
            }
        }
        cout << res << "\n";
    }
}
0