nefu119 组合素数 算术基本定理的应用

好难啊 看着好难的样子,一开始想直接化简C(2*n,n)的,可是后来发现还是不可以,网上也是没有这道题目的题解的,后来看看题目的名字 叫做组合素数,就去翻了一些相关资料的书,最后居然找到了一个公式,我顿时蛋疼的要死啊,这个公式 我也证不出来,唉~我太水太菜了,不过还是要牢牢记住这个公式,毕竟比赛的时候不可能让你带本书的,据说规定修改了 不能带超过 多少页的 资料,而且必须是只能单面有资料

因为题目中给定的p是素数,所以可以用这个公式,感觉这个式子跟算术基本定理的性质5相关

公式:([2*n/p]-2*[n/p])+([2*n/p^2]-2*[n/p^2])+([2*n/p^3]-2*[n/p^3])+......+([2*n/p^t]-2*[n/p^t])

其中 t=log(p)(2*n),这个log的式子很不好表达这个式子 可以写成 log10(2*n)/log(p),如果觉得我原式子写的不清楚的,可以利用 现在这个式子反化简过去


#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>

#define ll long long
#define LL __int64
#define eps 1e-8
#define e 2.718281828

//const ll INF=9999999999999;

#define M 400000100

#define inf 0xfffffff

using namespace std;

//vector<pair<int,int> > G;
//typedef pair<int,int> P;
//vector<pair<int,int>> ::iterator iter;
//
//map<ll,int>mp;
//map<ll,int>::iterator p;
//
//vector<int>G[30012];

int main(void)
{
	int t;
	int n,p;
	cin>>t;
	while(t--)
	{
		cin>>n>>p;
		double t=log10(2.0*n)/log10(p*1.0);
		int s=int(t);
		int ans=0;
		int cnt=1;
		int temp=1;
		while(cnt<=s)
		{
			temp=temp*p;
			ans+=(2*n/temp)-2*(n/temp);
			cnt++;
		}
		cout<<ans<<endl;
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值