hdu-2204 Eddy's爱好 nyoj 526
生活随笔
收集整理的這篇文章主要介紹了
hdu-2204 Eddy's爱好 nyoj 526
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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次方的數(shù)有多少個(gè),每次把1去掉,最后的結(jié)果再加1return (LL)(pow(n*1.0,1.0 / x) + eps) - 1; } void solve(){//根據(jù)容斥原理奇加偶減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; }總結(jié)
以上是生活随笔為你收集整理的hdu-2204 Eddy's爱好 nyoj 526的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里立秋:AI千人千面,淘宝如何做智能化
- 下一篇: zoj-3802-Easy 2048 A