您的位置:首页 > 其它

qwb与小数

2017-06-02 10:13 106 查看
oj地址:http://115.231.222.240:8081/JudgeOnline/

Problem K: qwb与小数

Time Limit: 1 Sec  Memory Limit:
128 MB
Submit: 284  Solved: 40

[Submit][Status][Web
Board]

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


相当于求小数是一直乘十取模,思想很简单,要取得时候再除。PS:这个第0界之江校赛,很庆幸自己拿了一血,虽然很水。。。第一次在很多人面前拿一血。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 40000 + 10;
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x )
typedef long long ll;
#define eps 10e-10
const ll Mod = 100000000;
typedef pair<ll, ll> P;
ll gcd(ll x,ll y)
{
return y ? gcd(y,x % y) : x;
}
ll pow_mod(ll x,ll n,ll mod_val)
{
ll ans = 1;
ll t = x % mod_val;
while(n)
{
if(n & 1)
{
ans = ans * t % mod_val;
}
n >>= 1;
t = t * t % mod_val;
}
return ans;
}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if(b == 0)
{
d = a;x = 1;y = 0;
return ;
}
ex_gcd(b,a % b,d,y,x);
y -= a / b * x;
}
int main()
{
ll x,y,n;
while( ~ scanf("%lld%lld%lld",&x,&y,&n))
{
x %= y;
ll ans = x * pow_mod(10,n - 1,y) % y;
printf("%lld\n",ans * 10 / y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: