Time Limit: 4000/2000MS (Java/Others)
Memory Limit: 65535/65535KB (Java/Others)
30
Sample Output
19
Source
UESTC Training for Math
题目链接:http://acm.uestc.edu.cn/#/problem/show/618
题目分析:又是无平方因子数,比BZOJ那题简单很多,直接算就行了,参照BZOJ 2440
#include <cstdio> #include <cstring> #include <algorithm> #define ll long long using namespace std; int const MAX = 1e6 + 5; int mob[MAX], p[MAX]; bool prime[MAX]; void Mobius() { int pnum = 0; memset(prime, true, sizeof(prime)); mob[1] = 1; for(int i = 2; i < MAX; i++) { if(prime[i]) { p[pnum ++] = i; mob[i] = -1; } for(int j = 0; j < pnum && i * p[j] < MAX; j++) { prime[i * p[j]] = false; if(i % p[j] == 0) { mob[i * p[j]] = 0; break; } mob[i * p[j]] = -mob[i]; } } } ll cal(ll n) { ll cnt = 0; for(ll i = 1; i * i <= n; i++) cnt += (ll) mob[i] * (n / (i * i)); return cnt; } int main() { Mobius(); int T; scanf("%d", &T); while(T --) { ll n; scanf("%lld", &n); printf("%lld\n", cal(n)); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
UESTC 618 无平方因子数 (容斥 + 莫比乌斯反演)
原文地址:http://blog.csdn.net/tc_to_top/article/details/47275439