hdu-2204 Eddy's爱好 nyoj 526
生活随笔
收集整理的这篇文章主要介绍了
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的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 阿里立秋:AI千人千面,淘宝如何做智能化
- 下一篇: zoj-3802-Easy 2048 A