結果
問題 |
No.1006 Share an Integer
|
ユーザー |
![]() |
提出日時 | 2020-03-06 23:19:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,776 bytes |
コンパイル時間 | 902 ms |
コンパイル使用メモリ | 89,192 KB |
実行使用メモリ | 13,636 KB |
最終ジャッジ日時 | 2024-10-14 09:50:04 |
合計ジャッジ時間 | 4,486 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 4 TLE * 1 -- * 10 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i,n) for (int i = 0; i < (n); ++i) #define sort(a) sort((a).begin(), (a).end()); #define uniq(a) SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end()); #define find(a,x) find((a).begin(), (a).end(), (x)) != (a).end() #define reverse(a) reverse((a).begin(), (a).end()); #define out(d) cout << (d); #define outl(d) std::cout<<(d)<<"\n"; #define Yes() printf("Yes\n"); #define No() printf("No\n"); #define YES() printf("YES\n"); #define NO() printf("NO\n"); #define ceil(x, y) ((x + y - 1) / (y)) using namespace std; using ll = long long; using P = pair<ll,ll>; const ll MOD = 1000000007; // 10^9 + 7 // 約数の個数 int d(ll n) { int ret = 0; ll lim = ll(sqrt(n)); for (ll i = 1; i <= lim; i++) { if (n % i > 0) continue; ret += 2; if (i == n / i) ret--; } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); srand((unsigned)time(NULL)); ll n; cin >> n; priority_queue<P, vector<P>, greater<P>> q; ll min = 100000000; for (int i = 1; i <= n / 2; i++) { ll sub = abs(i - d(i) - (n - i - d(n - i))); // cout << "i = " << i << ", n - i = " << (n - i) << ", sub = " << sub << endl; if (sub < min) { q = decltype(q)(); q.push(make_pair(i, n - i)); q.push(make_pair(n - i, i)); min = sub; } else if (sub == min) { q.push(make_pair(i, n - i)); q.push(make_pair(n - i, i)); } } while (!q.empty()) { cout << q.top().first << " " << q.top().second << endl; q.pop(); } }