和上一题一样,注意除不尽为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的更多相关文章

  1. NEFU 118 - n!后面有多少个0 & NEFU 119 - 组合素数 - [n!的素因子分解]

    首先给出一个性质: n!的素因子分解中的素数p的幂为:[ n / p ] + [ n / p² ] + [ n / p³ ] + …… 举例证明: 例如我们有10!,我们要求它的素因子分解中2的幂: ...

  2. Entity Framework 6 Recipes 2nd Edition(11-9)译 -> 在LINQ中使用规范函数

    11-9. 在LINQ中使用规范函数 问题 想在一个LINQ查询中使用规范函数 解决方案 假设我们已经有一个影片租赁(MovieRental )实体,它保存某个影片什么时候租出及还回来,以及滞纳金等, ...

  3. 数论 - 算数基本定理的运用 --- nefu 118 : n!后面有多少个0

     题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemshow.php Mean: 略. analyse: 刚开始想了半天都没想出来,数据这么大,难道是有什么 ...

  4. 118. 119. Pascal's Triangle -- 杨辉三角形

    118. Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...

  5. leetcode 119

    119. Pascal's Triangle II Given an index k, return the kth row of the Pascal's triangle. For example ...

  6. 【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, ...

  7. 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 ...

  8. 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 ...

  9. C程序设计语言练习题1-19

    练习1-19 编写函数reverse(s),将字符串s中的字符顺序颠倒过来.使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序.代码如下: #include <stdio.h> // ...

随机推荐

  1. 【Python学习笔记】-APP图标显示未读消息数目

    以小米手机系统为例,当安装的某个APP有未读消息时,就会在该APP图标的右上角显示未读消息的数目.本文主要解说怎样用Python语言实现图标显示未读消息的数目.首先,还是要用到Python中PIL库, ...

  2. python spark 决策树 入门demo

    Refer to the DecisionTree Python docs and DecisionTreeModel Python docs for more details on the API. ...

  3. 【撸码caffe 三】 caffe.cpp

    caffe.cpp文件完成对网络模型以及模型配置参数的读入和提取,提供了网络模型训练的入口函数train和对模型的测试入口函数test.文件中使用了很多gflags和glog指令,gflags是goo ...

  4. 如何提升SQL语句的查询性能

    在对数据库进行操作时,如果SQL语句书写不当,对程序的效率会造成很大影响. 提高SQL效率可以从一下几个方面入手: 1,数据库设计与规划 Primary Key字段的长度尽量小,能用small int ...

  5. 用WPF做关于MEF 简单学习记录

    写在前面:下面学习所得多是从自http://www.cnblogs.com/comsokey/p/MEF1.html和http://www.cnblogs.com/yunfeifei/p/392266 ...

  6. IP与以太网的包收发操作

    你好,这是<网络是怎样连接的>的第3篇读书笔记,第二章<用电信号传输TCP/IP>后半部分:IP与以太网的包收发操作. 先看下经典的TCP/IP四层模型: 通常,下层模块支撑上 ...

  7. Hadoop MapReduce编程 API入门系列之wordcount版本4(八)

    这篇博客,给大家,体会不一样的版本编程. 是将map.combiner.shuffle.reduce等分开放一个.java里.则需要实现Tool. 代码 package zhouls.bigdata. ...

  8. url 域名 主机名

    1. url = 协议//主机名(包括服务器的计算机名+域名)/路径 https:// i. cnblogs.com /index.html .com是顶级域名,从右向左,每碰到一个".&q ...

  9. [Offer收割]编程练习赛41

    比赛日程安排 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #incl ...

  10. (转载)自定义CoordinatorLayout的Behavior(2):实现淘宝和QQ ToolBar透明渐变效果

    自定义CoordinatorLayout的Behavior(2):实现淘宝和QQ ToolBar透明渐变效果 作者 小武站台 关注 2016.02.19 11:34 字数 1244 阅读 3885评论 ...