您的位置:首页 > 其它

NEFU 119 组合素数

2014-05-16 19:21 239 查看
公式没搞懂。。。(( [2*n/p]-2*[n/p] ) + ( [2*n/p^2]-2*[n/p^2] ) +...+ ( [2*n/p^t]-2*[n/p^t] ))其中t = [logp(2*n)]

注意精度

代码如下:

#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,p;
double temp;
int cnt = 1;
int t,ans;
scanf("%d%d",&n,&p);

temp = log10(2.0*n)*1.0/log10(p);
t = int(temp);
//printf("temp = %.2lf\n",temp);
//printf("t = %d\n",t);
ans = 0;
for(int i = 1;i <= t;i++)
{
cnt = cnt*p;
ans += (int)(2.0*n/cnt) - 2*(int)(n/cnt);
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: