結果
問題 | No.2125 Inverse Sum |
ユーザー | Lê Hoàng Ngô |
提出日時 | 2024-06-29 14:45:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 1 ms
6,948 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
コンパイルメッセージ
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(); } }