TYVJ1658 奶牛同盟

就是线性筛嘛。。

线性筛到处都有,本蒟蒻就不没事介绍了。

Code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int getlog(int a,int b){
	return log(b)/log(a);
}

int f[10000001],p[1000001];

int main(){
	int n,tot=0;
	cin >>n;
	for (int i=2;i<=n;i++){
		if (!f[i]) p[++tot]=i;
		for (int j=1;(j<=tot)&&(i*p[j]<=n);j++){
		    f[i*p[j]]=1;
		    if (i%p[j]==0) break;
		}
	}
	unsigned long long ans=1;
	for (int i=1;i<=tot;i++) ans+=pow(p[i],getlog(p[i],n));
	cout <<tot+1 <<" " <<ans <<endl;
	return 0;
}

 

posted @ 2012-06-02 21:49  JS_Shining  阅读(171)  评论(0编辑  收藏  举报