Ma đạo solution FRACTION - Số chữ số thập phân :D
Nguyễn Hoàng Sơn
2021-06-12 3:52:14
2021-06-12 3:52:26
//Hoang Son WIBU lolicon codeforces rate 1642 khong cay
#include <bits/stdc++.h>
#define F first
#define S second
#define times double stime = clock();
#define gettime cerr << "\nTime executed: " << (clock() - stime) / CLOCKS_PER_SEC * 1000 << "ms.\n";
using namespace std;
typedef long long ll;
typedef double dou;
typedef pair<ll, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const ll mod = 1000000009;
ll n;
ll powi(ll ax, ll bx){
if(bx == 0) return 1;
if(bx == 1) return ax;
ll cx = powi(ax, bx/2);
cx = cx*cx;
if(bx%2) cx *= ax;
return cx;
}
int numo(ll ax, ll bx){
int l = 0, r = 9, ans = 9;
while(l<=r){
int mid = (l+r)/2;
if(ax*powi(10ll, mid) >= bx){
r = mid - 1;
ans = mid;
} else l = mid + 1;
}
return ans;
}
map<int, bool> mp;
void process(){
cin >> n;
int ans = 0;
ll kd = 1;
while(kd%n){
if(ans > 100000){
ans = -1;
break;
}
if(kd < n){
int j = numo(kd, n);
ans += j;
kd = kd*powi(10ll, j);
}
if(mp[kd] == true){
ans = -1;
break;
}
mp[kd] = true;
kd %= n;
}
if(ans == -1){
cout << "NO";
} else {
cout << ans;
}
}
int online = 2;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (online == 0) {
freopen("in.inp", "r", stdin);
freopen("out.out", "w", stdout);
} else if (online == 1) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
// times
process();
// gettime
return 0;
}