Description
qwb遇到了一个问题:将分数a/b化为小数后,小数点后第n位的数字是多少?
做了那么多题,我已经不指望你能够帮上他了。。。
Input
多组测试数据,处理到文件结束。(测试数据<=100000组)
每组测试例包含三个整数a,b,n,相邻两个数之间用单个空格隔开,其中0 <= a <1e9,0 < b < 1e9,1 <= n < 1e9。
Output
对于每组数据,输出a/b的第n位数,占一行。
Sample Input
1 2 1
1 2 2
Sample Output
5
0
Hint
题意
分数a/b化为小数后,小数点后第n位的数字是多少
题解:
挺有意思的一个题 感觉以前好像见过啊 快速幂搞定
AC代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL Pow (LL a, LL b,LL c)
{
LL ans = 1;
while(b) {
if(b&1) ans = ans*a%c;
b /= 2;
a = a*a%c;
}
return ans;
}
int main()
{
LL a, b, k;
while(~scanf("%lld%lld%lld",&a,&b,&k)) {
printf("%lld\n",a*Pow(10,k-1,b)%b*10/b);
}
return 0;
}