結果

問題 No.1203 お菓子ゲーム
ユーザー chocorusk
提出日時 2020-08-29 04:27:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 571 ms / 2,000 ms
コード長 1,500 bytes
コンパイル時間 4,299 ms
コンパイル使用メモリ 135,728 KB
最終ジャッジ日時 2025-01-13 19:59:00
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

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 && a1/x>b && a1/x<=M) 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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0