码迷,mamicode.com
首页 > 其他好文 > 详细

qwb与小数

时间:2017-06-03 15:18:17      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:mat   pair   make   algorithm   back   cond   bit   数字   cas   

qwb与小数

Time Limit: 1 Sec  Memory Limit: 128 MB

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
分析:a/b后小数点第n位,因为一直*10%b,最后*10/b,快速幂就好了;
代码:
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <algorithm> 
#include <climits> 
#include <cstring> 
#include <string> 
#include <set> 
#include <bitset> 
#include <map> 
#include <queue> 
#include <stack> 
#include <vector> 
#include <cassert> 
#include <ctime> 
#include<unordered_map> 
#define rep(i,m,n) for(i=m;i<=n;i++) 
#define mod 1000000007 
#define inf 0x3f3f3f3f 
#define vi vector<int> 
#define pb push_back 
#define mp make_pair 
#define fi first 
#define se second 
#define ll long long 
#define pi acos(-1.0) 
#define pii pair<int,int> 
#define sys system("pause") 
#define ls rt<<1 
#define rs rt<<1|1 
const int maxn=1e3+10; 
const int N=5e2+10; 
using namespace std; 
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} 
int n,m,k,t; 
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%m;p=p*p%m;q>>=1;}return f;} 
  
int main() 
{ 
    int i,j; 
    while(~scanf("%d%d%d",&n,&m,&k)) 
    { 
        printf("%lld\n",(n%m)*qpow(10,k-1)%m*10/m); 
    } 
    return 0; 
} 

qwb与小数

标签:mat   pair   make   algorithm   back   cond   bit   数字   cas   

原文地址:http://www.cnblogs.com/dyzll/p/6937252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!