qwb与小数
2017-06-02 10:13
106 查看
oj地址:http://115.231.222.240:8081/JudgeOnline/
128 MB
Submit: 284 Solved: 40
[Submit][Status][Web
Board]
做了那么多题,我已经不指望你能够帮上他了。。。
每组测试例包含三个整数a,b,n,相邻两个数之间用单个空格隔开,其中0 <= a <1e9,0 < b < 1e9,1 <= n < 1e9。
相当于求小数是一直乘十取模,思想很简单,要取得时候再除。PS:这个第0界之江校赛,很庆幸自己拿了一血,虽然很水。。。第一次在很多人面前拿一血。
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; }
相关文章推荐
- 之江学院 K: qwb与小数(思维求A/B第n位小数)
- 之江学院第0届校赛决赛 K-qwb与小数
- 之江学院2017ACM 校赛 Problem K: qwb与小数(思维 快速幂)
- 江学院-Problem K: qwb与小数
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 K: qwb与小数 [快速幂]【思维】
- qwb与小数 思路+代码
- 之江学院 K: qwb与小数(思维求A/B第n位小数)
- java中如何使Double类型的数值保留两位小数问题
- 精确计算PI小数点后800位小数
- JS小数运算出现多位小数的问题
- 列出SQL SERVER 所有表,字段名,主键,类型,长度,小数位数等信息
- mysql存小数
- VB实现小数和分数的相互转化
- 小数转分数
- 小数的循环节
- 判断字符串中是否是整数和小数的方法
- asp.net(c#)中,两个整数相除,怎样得到带小数点的结果呢?
- Android EditText 输入数据时限制小数位数。
- 以指定形式格式化小数到描述符
- 将一个double型数值保留两位小数