牛客 43(B 小数点后的第k1至k2位)

https://ac.nowcoder.com/acm/contest/548/B

题解:可以自己手动模拟一下,然后你会发现,一个数除的最后一位只与上一位的余有关。所以,不断 *10 然后 %b 就好。但是太慢。。加个快速幂。a*(10,n-1) %b 然后 剩下的 *10再/b 就好

#include<bits/stdc++.h>
#define MID (l+r)>>1
#define lson step<<1
#define rson step<<1|1
#define LL long long
using namespace std;
const int maxn=1005;
LL m,n,k1,k2;
LL qpow(LL c,LL d)
{
    LL res=1;
    while(d)
    {
        if(d&1)
            res*=c,res%=n;
        c*=c;
        c%=n;   
        d>>=1;
    }
    return res%n;
} 
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>m>>n>>k1>>k2;
		for(int i=k1;i<=k2;i++)
		{
			LL z=(m%n*qpow(10,i-1))%n;
    		cout << z*10/n;
		}
		cout << endl;
	}
	

	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值