結果

問題 No.1203 お菓子ゲーム
ユーザー chocoruskchocorusk
提出日時 2020-08-28 23:25:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 140,636 KB
実行使用メモリ 42,844 KB
最終ジャッジ日時 2024-04-26 13:58:39
合計ジャッジ時間 14,441 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 213 ms
42,588 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 205 ms
42,676 KB
testcase_19 AC 196 ms
42,504 KB
testcase_20 AC 192 ms
42,692 KB
testcase_21 WA -
testcase_22 AC 179 ms
42,668 KB
testcase_23 AC 188 ms
42,584 KB
testcase_24 AC 203 ms
42,636 KB
testcase_25 AC 206 ms
42,596 KB
testcase_26 WA -
testcase_27 AC 200 ms
42,688 KB
testcase_28 AC 194 ms
42,560 KB
testcase_29 AC 204 ms
42,508 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 229 ms
42,480 KB
testcase_49 WA -
testcase_50 AC 190 ms
42,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX=10000010;
int p[MAX];
void sieve(){
	for(int i=2; i<MAX; i++){
		if(p[i]==0){
			for(int j=(i<<1); j<MAX; j+=i) p[j]=i;
		}
	}
}
void dfs(int k, int x, int y, vector<P> v, vector<ll> &w){
	if(k==v.size()){
		if(x>1 && x%2==1){
        	w.push_back(x);
        }
		return;
	}
	ll q=1;
	for(int i=0; i<=v[k].second; i++){
		dfs(k+1, x*q, y, v, w);
		q*=v[k].first;
	}
}
vector<ll> divisor(ll y){
	vector<ll> w;
	ll y1=y;
	map<int, int> f;
	while(p[y]>0){
		f[p[y]]++;
		y/=p[y];
	}
	f[y]++;
	vector<P> v;
	for(auto p:f) v.push_back(p);
	dfs(0, 1, y1, v, w);
	return w;
}
const ll M=1e8;
ll solve(ll x, ll y){
	if(x*2==y) return 0;
	if(x*2>y) x=y-x;
	ll ans=M/y;
	auto v=divisor(y);
	for(auto b:v){
		ll a1=(b-1)*((b+1)/2)*(y/b);
		if(a1%x==0) ans++;
	}
	return ans;
}
int main()
{
	int s; cin>>s;
	sieve();
	while(s--){
		ll x, y; cin>>x>>y;
    	cout<<solve(x, y)<<endl;
	}
	return 0;
}
0