欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

hdu-2204 Eddy's爱好 nyoj 526

发布时间:2025/3/16 编程问答 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 hdu-2204 Eddy's爱好 nyoj 526 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

hdu : http://acm.hdu.edu.cn/showproblem.php?pid=2204  

nyoj :  http://acm.nyist.net/JudgeOnline/problem.php?pid=526   

题解:容斥原理

#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> using namespace std; typedef long long LL; #define eps 1e-8 LL prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61}; LL a[] = {6,10,14,15,21,22,26,33,34,35,38,39,46,51,55,57,58,62}; LL n; LL find(LL x){ //找1~n中开根号x次方的数有多少个,每次把1去掉,最后的结果再加1return (LL)(pow(n*1.0,1.0 / x) + eps) - 1; } void solve(){//根据容斥原理奇加偶减LL sum = 0;for(int i = 0;i < 18;i++)sum += find(prime[i]);sum += find(30);// 2 * 3 * 5sum += find(42);// 2 * 3 * 7for(int i = 0;i < 18;i++)sum -= find(a[i]);printf("%lld\n",sum+1); } int main(){while(~scanf("%lld",&n)){solve();}return 0; }

总结

以上是生活随笔为你收集整理的hdu-2204 Eddy's爱好 nyoj 526的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。