链接:https://ac.nowcoder.com/acm/contest/548/B
来源:牛客网
第一行一个整数 T,表示有 T 组数据。
接下来每行包含四个整数 m,n,K1,K2m,n,K1,K2,意义如「题目描述」所示。
输出 T 行,每行输出 K2−K1+1K2−K1+1 个数,表示答案。
注意同行的数字中间不需要用空格隔开。
5
2 3 2 3
1 7 1 7
2 5 1 3
12345 54321 3 10
12345 54321 100000 100010
66
1428571
400
72601756
78428232175
思路:求第k1位的数字 其实就是 m*10^(k-1)对n求模 所以用快速幂处理一下 然后就模拟短除法就行了
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define ll long long int using namespace std; inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int dir[4][2]={1,0 ,0,1 ,-1,0 ,0,-1}; int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1}; const int inf=0x3f3f3f3f; const ll mod=1e9+7; ll m,n,k1,k2; ll q_pow(ll a,ll n,ll mod){ ll ans=m; ll base=a; while(n){ if(n&1) ans=(ans*base)%mod; base=base*base%mod; n>>=1; } return ans; } int main(){ //ios::sync_with_stdio(false); int t; scanf("%d",&t); while(t--){ scanf("%lld%lld%lld%lld",&m,&n,&k1,&k2); ll f=q_pow(10,k1-1,n); ll i=k1; while(1){ f*=10; printf("%lld",f/n); f%=n; i++; if(i==k2+1) break; } printf("\n"); } }
牛客练习赛43 Tachibana Kanade Loves Probability(快速幂)
原文:https://www.cnblogs.com/wmj6/p/10660232.html