当前位置:网站首页>Trailing Zeroes (II)
Trailing Zeroes (II)
2022-06-28 08:35:00 【Angeliaaa】
Find the number of trailing zeroes for the following function:
nCr * pq
where n, r, p, q are given. For example, if n = 10, r = 4, p = 1, q = 1, then the number is 210 so, number of trailing zeroes is 1.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains four integers: n, r, p, q (1 ≤ n, r, p, q ≤ 106, r ≤ n).
Output
For each test case, print the case number and the number of trailing zeroes.
Sample Input
2
10 4 1 1
100 5 40 5
Sample Output
Case 1: 1
Case 2: 6
The question : seek c(n,r)*p^q Back guide of 0 The number of .
Ideas : We find the derivative of a number 0 This number is usually factorized to find 2 The number of 5 The number of , Then the smaller one is the end of the number 0 The number of , Because the number required by this question is in the form of division , Because of the molecular 2 And 5 It can be combined with the 2 And 5 Countervailing , So we need 2 Is the number of molecules 2 Subtract the number of from the denominator 2 The number of , seek 5 Is the number of molecules 5 Subtract the number of from the denominator 5 The number of , Then find a smaller one, which is the result , Because the data range of this question is large , So type a watch first , Use prefixes and two-dimensional arrays num【】【】,num【i】【0】 Array to store from 1 To i Medium factor 2 Total number of ,num【i】【1】 Array to store data from 1 To i Medium factor 5 Total number of . Finally, we can get the result by processing , The code is as follows :
#include<stdio.h>
#include<string>
#include<queue>
#include<math.h>
#define inf 0x3f3f3f3f
#define LL long long
#include<string.h>
#include<algorithm>
using namespace std;
int num[1000010][2]= {0};
void init()
{
num[1][0]=0;
num[1][1]=0;
for(int i=2; i<1000010; i++)
{
int x=i;
num[i][0]=num[i-1][0];
while(x%2==0)
{
num[i][0]++;
x=x/2;
}
int x1=i;
num[i][1]=num[i-1][1];
while(x1%5==0)
{
num[i][1]++;
x1=x1/5;
}
}
}
int main()
{
int T,cas=1;
init();
int n,r,p,q;
scanf("%d",&T);
while(T--)
{
int s2,s5;
scanf("%d %d %d %d",&n,&r,&p,&q);
s2=num[n][0]-num[r][0]-num[n-r][0]+(num[p][0]-num[p-1][0])*q;
s5=num[n][1]-num[r][1]-num[n-r][1]+(num[p][1]-num[p-1][1])*q;
printf("Case %d: ",cas++);
if(s2>s5)
printf("%d\n",s5);
else
printf("%d\n",s2);
}
return 0;
}
边栏推荐
- Almost Union-Find(带权并查集)
- Discussion on the application of GIS 3D system in mining industry
- Leetcode swing series
- [untitled]
- 如何抑制SiC MOSFET Crosstalk(串扰)?
- 解决npm ERR! Unexpected end of JSON input while parsing near问题
- Hidden scroll bar on PC
- Tree
- Chenglian premium products donated love materials for flood fighting and disaster relief to Yingde
- B_ QuRT_ User_ Guide(30)
猜你喜欢

安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)

【云原生 | Kubernetes篇】深入了解Pod(六)
![[cloud native | kubernetes] in depth understanding of pod (VI)](/img/ae/f16f5c090251ab603b88ddadff7eb3.png)
[cloud native | kubernetes] in depth understanding of pod (VI)

Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu

WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持

Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support

PLSQL installation under Windows

About using font icons in placeholder
![DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...

Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
随机推荐
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...
Kubernetes notes and the latest k3s installation introduction
Comment supprimer le crosstalk SiC MOSFET?
A - Bi-shoe and Phi-shoe
The micro kernel zephyr is supported by many manufacturers!
VMware Workstation related issues
关于如何在placeholder中使用字体图标
AWS builds a virtual infrastructure including servers and networks (2)
新唐NUC980使用记录:自制开发板(基于NUC980DK61YC)
Not so Mobile
Quelle est la largeur de bande du serveur de bavardage sonore pour des centaines de millions de personnes en même temps?
PLSQL installation under Windows
js取整的小技巧
Ffmpeg (I) AV_ register_ all()
Cloudcompare & PCL point cloud SVD decomposition
Priority of JS operator
duilib 入门基础十二 样式类
The RAC cannot connect to the database normally after modifying the scan IP. The ora-12514 problem is handled
Why are function templates not partial specialization?
Sword finger offer 30 Stack containing min function