結果
| 問題 |
No.1464 Number Conversion
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-02 22:15:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,070 ms / 2,000 ms |
| コード長 | 1,495 bytes |
| コンパイル時間 | 1,554 ms |
| コンパイル使用メモリ | 170,768 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-23 19:49:24 |
| 合計ジャッジ時間 | 31,115 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function 'long long int solve()':
main.cpp:46:8: warning: 'cd' may be used uninitialized [-Wmaybe-uninitialized]
46 | cd /= g;
| ~~~^~~~
main.cpp:32:13: note: 'cd' was declared here
32 | int cx, cd;
| ^~
main.cpp:45:8: warning: 'cx' may be used uninitialized [-Wmaybe-uninitialized]
45 | cx /= g;
| ~~~^~~~
main.cpp:32:9: note: 'cx' was declared here
32 | int cx, cd;
| ^~
ソースコード
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;
const int M = 1e16;
int solve() {
double dx, md = 10;
cin >> dx;
int cx, cd;
string ans;
for(int d = 1; d * d <= M; d++) {
if(M % d) continue;
int x = round(d * dx);
double dist = abs(d * dx - x);
int g = __gcd(x, d);
if(dist < md) {
md = dist;
cx = x, cd = d;
}
}
int g = __gcd(cx, cd);
cx /= g;
cd /= g;
ans = to_string(cx) + "/" + to_string(cd);
cout << ans << endl;
return 0;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}