NEFU 119
和上一题一样,注意除不尽为0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; long long n,p; int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&n,&p);
int a,b;
a=b=0;
for(long long i=p;i<=n*2;i*=p)
a+=((2*n)/i);
for(long long i=p;i<=n;i*=p)
b+=(n/i);
long long tmp=a-b-b;
printf("%lld\n",tmp>0?tmp:0);
}
return 0;
}
NEFU 119的更多相关文章
- NEFU 118 - n!后面有多少个0 & NEFU 119 - 组合素数 - [n!的素因子分解]
首先给出一个性质: n!的素因子分解中的素数p的幂为:[ n / p ] + [ n / p² ] + [ n / p³ ] + …… 举例证明: 例如我们有10!,我们要求它的素因子分解中2的幂: ...
- Entity Framework 6 Recipes 2nd Edition(11-9)译 -> 在LINQ中使用规范函数
11-9. 在LINQ中使用规范函数 问题 想在一个LINQ查询中使用规范函数 解决方案 假设我们已经有一个影片租赁(MovieRental )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...
- 数论 - 算数基本定理的运用 --- nefu 118 : n!后面有多少个0
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php Mean: 略. analyse: 刚开始想了半天都没想出来,数据这么大,难道是有什么 ...
- 118. 119. Pascal's Triangle -- 杨辉三角形
118. Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- leetcode 119
119. Pascal's Triangle II Given an index k, return the kth row of the Pascal's triangle. For example ...
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...
- Word Properties <?ref:xdo000X?> - BIP Deskotop 11.119.00.0 (32-bit) with Office 2013 (32-bit) on Win 7 64-bit
BIP Deskotop 11.119.00.0 (32-bit)Office 2013 (32-bit)Win 7 (64-bit)The current certification matrix ...
- Struts 2.x异常:Unable to load configuration..../WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/struts-plugin.xml:30:119
Struts 2.x异常:Unable to load configuration..../WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/strut ...
- C程序设计语言练习题1-19
练习1-19 编写函数reverse(s),将字符串s中的字符顺序颠倒过来.使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序.代码如下: #include <stdio.h> // ...
随机推荐
- Java深入 - Filter过滤器
Java的1.3開始,对servlet2.3规范中增加了过滤器的支持.过滤器可以让我们对目标资源的请求和响应进行截取. 一些filter的特性: 1. Filter是Servlet规范的规定,须要Se ...
- Code Coverage and Unit Test in SonarQube
概念 https://blog.ndepend.com/guide-code-coverage-tools/ Code Coverage Results Import (C#, VB.NET) Uni ...
- MySql查询系统时间,SQLServer查询系统时间,Oracle查询系统时间
转自:https://blog.csdn.net/haleyliu123/article/details/70927668/ MySQL查询系统时间 第一种方法:select current_date ...
- ROS单线多拨pppoe
#设置内网IP地址 / ip add add interface=ether1 address=192.168.0.254/255.255.255.0 #设置共享上网 / ip firewall na ...
- MyBatis输出执行的SQL到控制台
src\main\resources\application.properties 或者src\main\resources\application.yml 在你的application.proper ...
- wolf
package com.wh.Demo50; /** * @author 王恒 * @datetime 2017年4月7日 下午4:40:54 * @description * 分析:子类重写父类的方 ...
- 使用C#正则表达式获取必应每日图片地址
微软的Bing搜索引擎首页每天都会提供了一些有趣的图片,下面使用正则表达式获取图片的地址,不管是在手机app还是在网站上都是很好的图片素材,而且每天更新,非常不错. 首先访问微软的API,该地址返回的 ...
- Android线程间异步通信机制源码分析
本文首先从整体架构分析了Android整个线程间消息传递机制,然后从源码角度介绍了各个组件的作用和完成的任务.文中并未对基础概念进行介绍,关于threadLacal和垃圾回收等等机制请自行研究. 基础 ...
- ffmpeg编码
1. 注册所有容器格式和CODEC:av_register_all()2. 打开文件:av_open_input_file()3. 从文件中提取流信息:av_find_stream_info()4. ...
- Fiddler-AutoResponder 修改接口数据
问题 App 功能测试时,有些场景需要特殊的数据,如 App 对极限值的处理:或是账单列表的时间需要显示刚刚.昨天.周几,需要接口返回不同的时间.更改数据库是一种方法,但不够灵活,一些复杂的场景也不好 ...