题目链接:
PREV-52 小数第n位
思路:
根据题意可知答案为
由于n较大,可用快速幂求取
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pow_mod(ll x, ll n, ll mod) {
ll res = 1;
while(n) {
if(n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
ll a, b, n;
cin >> a >> b >> n;
a = abs(a), b = abs(b);
a = a * pow_mod(10, n - 1, b) % b;
a *= 1000;
cout << a / b;
return 0;
}