結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2015-03-22 02:18:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,491 bytes |
| コンパイル時間 | 824 ms |
| コンパイル使用メモリ | 85,872 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-15 21:10:53 |
| 合計ジャッジ時間 | 1,565 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%lld%lld", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1000000009;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a%b);
}
P finite(ll k) {
P p = P(0, 0);
while (k % 2 == 0) {
k /= 2;
p.first++;
}
while (k % 5 == 0) {
k /= 5;
p.second++;
}
return (k == 1 ? p : P(-1, -1));
}
int main() {
ll n, m;
scanf("%lld%lld", &n, &m);
ll g = gcd(n, m);
n /= g;
m /= g;
P p = finite(m);
if (p.first < 0) {
printf("-1\n");
} else {
while (n % 10 == 0) n /= 10;
int d = n % 10;
if (p.second > 0) {
int a[4] = {6, 2, 4, 8};
d *= a[p.second%4];
}
if (p.first > 0) {
d *= 5;
}
while (d % 10 == 0) d /= 10;
printf("%d\n", d%10);
}
}
assy1028