結果
問題 | No.2125 Inverse Sum |
ユーザー |
|
提出日時 | 2024-06-29 14:45:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,345 bytes |
コンパイル時間 | 1,849 ms |
コンパイル使用メモリ | 179,908 KB |
実行使用メモリ | 7,068 KB |
最終ジャッジ日時 | 2024-06-29 14:45:13 |
合計ジャッジ時間 | 3,397 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 8 |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:66:37: warning: narrowing conversion of '((d + Q) / P)' from 'long long int' to 'int' [-Wnarrowing] 66 | ans.push_back( {(d + Q) / P, (dd + Q) / P}); | ~~~~~~~~^~~ main.cpp:66:37: warning: narrowing conversion of '((d + Q) / P)' from 'long long int' to 'int' [-Wnarrowing] main.cpp:66:51: warning: narrowing conversion of '((dd + Q) / P)' from 'long long int' to 'int' [-Wnarrowing] 66 | ans.push_back( {(d + Q) / P, (dd + Q) / P}); | ~~~~~~~~~^~~ main.cpp:66:51: warning: narrowing conversion of '((dd + Q) / P)' from 'long long int' to 'int' [-Wnarrowing]
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater<int>()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} const int MOD = 998244353; const int N = 5e5 + 5; const ll INF = 1e16; // https://yukicoder.me/problems/no/2125 // given p,q find how many (n,m) that satisfy: // 1 / n + 1 / m = p / q // mq + nq = pnm // (pn-q)m - nq = 0 // (pn-q)mp - pqn = 0 // (pn-q)mp - (pn-q)q = q*q // (pn-q)(pm-q)=q*q vector<ll> divisor(ll x){ vector<ll> ans; for (ll i = 1; i * i <= x; i++){ if (x % i == 0){ ans.push_back(i); if (x / i != i) ans.push_back(x/i); } } return ans; } vector<ll> divisor_of_square(ll x){ set<ll> st; vl div = divisor(x); rep(i,0,sz(div)-1) rep(j,i,sz(div)-1) st.insert(div[i] * div[j]); vl ans; each(st,y) ans.push_back(y); return ans; } void solve(){ ll P,Q; cin >> P >> Q; ll G = __gcd(P,Q); P /= G, Q /= G; vector<vector<int>> ans; vl div = divisor_of_square(Q); each(div, d){ // cout << d << nl; ll dd = Q * Q / d; if ( (d + Q) % P == 0 && (dd + Q) % P == 0) { ans.push_back( {(d + Q) / P, (dd + Q) / P}); } } cout << sz(ans) << nl; each(ans,v) cout << v[0] << ' ' << v[1] << nl; } void test() { ll mx = 0; rep(i,0.9e7,(int)1e7){ // chmax(mx, sz(factorization(i))); } cout << mx << nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; // test(); while (t--){ solve(); } }