博客
关于我
后导0
阅读量:306 次
发布时间:2019-03-03

本文共 845 字,大约阅读时间需要 2 分钟。

题目

这是一道很简单的中学数学题:

给定数n,求n!的p进制下有多少个后导零。非常简单。

为了简化问题,p保证为素数。
输入
第一行给定一个数t,表示有t组输入

接下来t行,每行给定两个数n,p;意义如题所示;

输入范围:(t<=1000) (1<=n<=1000000 ) (2<=p<=1000000)

样例

输入

22 23 2

输出

11

在这里插入图片描述

在这里插入图片描述

#include 
#include
#include
using namespace std;const int Max = 1e6+7;int main(){ int t,n,p,r; cin >> t; while(t--) { cin>>n>>p; while(n){ n=n/p; r=r+n; } cout<
<
#include 
int main(){ int t; scanf("%d",&t); int n,p; for(int i = 0;i < t;i++){ scanf("%d%d",&n,&p); int count = 0; for(int j = p;j <= n;j += p){ //找出所有p的倍数:1p,2p,3p... int k = j; while(k % p == 0){ //计算p的倍数中包含p个数,即要除以几次才能余数不为0,即0的个数 count++; k /= p; } } printf("%d\n",count); } return 0;}

转载地址:http://mrym.baihongyu.com/

你可能感兴趣的文章
Node.js的循环与异步问题
查看>>
Node.js高级编程:用Javascript构建可伸缩应用(1)1.1 介绍和安装-安装Node
查看>>
nodejs + socket.io 同时使用http 和 https
查看>>
NodeJS @kubernetes/client-node连接到kubernetes集群的方法
查看>>
NodeJS API简介
查看>>
Nodejs express 获取url参数,post参数的三种方式
查看>>
nodejs http小爬虫
查看>>
nodejs libararies
查看>>
vue3+element-plus 项目中 el-switch 刷新后自动触发change?坑就藏在这里!
查看>>
nodejs npm常用命令
查看>>
nodejs npm常用命令
查看>>
Nodejs process.nextTick() 使用详解
查看>>
NodeJS yarn 或 npm如何切换淘宝或国外镜像源
查看>>
nodejs 中间件理解
查看>>
nodejs 创建HTTP服务器详解
查看>>
nodejs 发起 GET 请求示例和 POST 请求示例
查看>>
NodeJS 导入导出模块的方法( 代码演示 )
查看>>
nodejs 开发websocket 笔记
查看>>
nodejs 的 Buffer 详解
查看>>
nodejs 的 path 模块详解
查看>>