結果
問題 |
No.1203 お菓子ゲーム
|
ユーザー |
![]() |
提出日時 | 2020-08-28 23:25:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,479 bytes |
コンパイル時間 | 1,718 ms |
コンパイル使用メモリ | 136,384 KB |
最終ジャッジ日時 | 2025-01-13 19:40:15 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 38 |
ソースコード
#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; }