nefu 118 质数在阶乘中的幂 http://acm.nefu.edu.cn/test/problemshow.php?problem_id=118

#include<iostream>
#include<cmath>
using namespace std;

int  main()
{
  int k;
  cin>>k;
  int n;

  while(cin>>n)
  {
      int  exponent=0;
    for(int i=1;pow(5.0,i)<=n;i++)
    exponent+=n/pow(5.0,i);

    cout<<exponent<<endl;

  }
}

//应该发现 2的幂总比5高; 所以5的幂次等于零的个数

// 阶乘中求质数的幂的方法

利用这个结论还可以求质数在组合数中的幂  如 nefu 119  http://acm.nefu.edu.cn/test/problemshow.php?problem_id=119

#include<iostream>
#include<cmath>
using namespace std;

int  main()
{
  int k;
  cin>>k;
  int n;
  double p;

  while(cin>>n>>p)
  {

    int  exponent=0;
    for(int i=1;pow(p,i)<=n;i++)
      exponent+=n/pow(p,i);


    int  exponent1=0;
    for(int i=1;pow(p,i)<=n*2;i++)
    exponent1+=2*n/pow(p,i);

    cout<<exponent1-exponent*2<<endl;

  }
}


转载于:https://www.cnblogs.com/814jingqi/p/3217973.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值