【bzoj 3739】DZY loves math VIII - 乱搞数学题
来源:互联网 发布:苹果频谱电脑软件 编辑:程序博客网 时间:2024/05/26 02:55
说了这么多这题其实就是求
首先注意到当
因为
以下是玄学= =
打一个表会发现
于是大力枚举有效的
这样xjb搞一搞,差点没跑过去= =
时间复杂度
233333333333333
/* I will chase the meteor for you, a thousand times over. Please wait for me, until I fade forever. Just 'coz GEOTCBRL.*/#include <bits/stdc++.h>using namespace std;#define fore(i,u) for (int i = head[u] ; i ; i = nxt[i])#define rep(i,a,b) for (int i = a , _ = b ; i <= _ ; i ++)#define per(i,a,b) for (int i = a , _ = b ; i >= _ ; i --)#define For(i,a,b) for (int i = a , _ = b ; i < _ ; i ++)#define Dwn(i,a,b) for (int i = ((int) a) - 1 , _ = (b) ; i >= _ ; i --)#define fors(s0,s) for (int s0 = (s) , _S = s ; s0 ; s0 = (s0 - 1) & _S)#define foreach(it,s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)#define mp make_pair#define pb push_back#define pii pair<int , int>#define fir first#define sec second#define MS(x,a) memset(x , (a) , sizeof (x))#define gprintf(...) fprintf(stderr , __VA_ARGS__)#define gout(x) std::cerr << #x << "=" << x << std::endl#define gout1(a,i) std::cerr << #a << '[' << i << "]=" << a[i] << std::endl#define gout2(a,i,j) std::cerr << #a << '[' << i << "][" << j << "]=" << a[i][j] << std::endl#define garr(a,l,r,tp) rep (__it , l , r) gprintf(tp"%c" , a[__it] , " \n"[__it == _])template <class T> inline void upmax(T&a , T b) { if (a < b) a = b ; }template <class T> inline void upmin(T&a , T b) { if (a > b) a = b ; }typedef long long ll;const int maxn = 10000003;const int maxm = 200007;const int mod = 1000000007;const int inf = 0x7fffffff;const double eps = 1e-7;typedef int arr[maxn];typedef int adj[maxm];inline int fcmp(double a , double b) { if (fabs(a - b) <= eps) return 0; if (a < b - eps) return -1; return 1;}inline int add(int a , int b) { return ((ll) a + b) % mod ; }inline int mul(int a , int b) { return ((ll) a * b) % mod ; }inline int dec(int a , int b) { return add(a , mod - b % mod) ; }inline int Pow(int a , int b) { int t = 1; while (b) { if (b & 1) t = mul(t , a); a = mul(a , a) , b >>= 1; } return t;}#define gc getchar#define idg isdigit#define rd RD<int>#define rdll RD<long long>template <typename Type>inline Type RD() { char c = getchar(); Type x = 0 , flag = 1; while (!idg(c) && c != '-') c = getchar(); if (c == '-') flag = -1; else x = c - '0'; while (idg(c = gc()))x = x * 10 + c - '0'; return x * flag;}inline char rdch() { char c = gc(); while (!isalpha(c)) c = gc(); return c;}#undef idg#undef gc// beginningarr vis , mu , v , S;int pr[maxn / 10] , ptt;int tot/* , cnt*/;int a[10001]/* , fr[100001]*/;ll ans[maxn];static int CLOCK;int x , res;void dfs(int p , int w) { if (p == tot + 1) { S[w] += x; res += mu[w] * S[w];// ++ CLOCK; return; } dfs(p + 1 , w); dfs(p + 1 , w * a[p]);}int N;inline void init() { mu[1] = 1 , v[1] = 1 , ans[1] = 1; rep (i , 2 , N) { if (!vis[i]) pr[++ ptt] = i , mu[i] = -1 , v[i] = i; rep (j , 1 , ptt) { int t = i * pr[j]; if (t > N) break; vis[t] = 1; if (i % pr[j] == 0) { v[t] = v[i]; break;} mu[t] = -mu[i] , v[t] = pr[j]; } } S[1] = 1; rep (i , 2 , N) if (mu[i]) { int t = i; tot = 0; while (t > 1) a[++ tot] = v[t] , t /= v[t]; res = 0; x = mu[i]; dfs(1 , 1); ans[i] = ans[i - 1] + res * x; } else ans[i] = ans[i - 1];// gout(CLOCK);}int n , m[1007];void input() { n = rd(); rep (i , 1 , n) m[i] = rd() , upmax(N , m[i]);}void solve() { init(); rep (i , 1 , n) printf("%lld\n" , ans[m[i]]);}int main() { #ifndef ONLINE_JUDGE freopen("data.txt" , "r" , stdin); #endif input(); solve(); return 0;}
0 0
- 【bzoj 3739】DZY loves math VIII - 乱搞数学题
- bzoj 3739 DZY loves math VIII
- bzoj 3739: DZY loves math VIII (数学)
- BZOJ3739: DZY loves math VIII
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- bzoj3739 DZY loves math VIII 莫比乌斯函数
- 【线性筛】【bzoj 3309】: DZY Loves Math
- BZOJ 3560 DZY Loves Math V 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- BZOJ 3512: DZY Loves Math IV
- [杜教筛] BZOJ 3512 DZY Loves Math IV
- 【BZOJ 3560】【数论】DZY Loves Math V
- bzoj 3309: DZY Loves Math (反演)
- java中静态域,静态常量,静态方法
- java数据库连接池学习
- form表单学习记录
- 定时任务管理中心(dubbo+spring)-我们到底能走多远系列47
- Vue.js 和 MVVM 小细节
- 【bzoj 3739】DZY loves math VIII - 乱搞数学题
- PopupWindow
- 定时任务管理中心(dubbo+spring)-我们到底能走多远系列48
- 冒泡排序和选择排序区别
- 滑动时收起键盘
- HiHoCoder1033交错和——数位dp
- 基带传输与成形滤波
- Linux下web服务器搭建需注意的问题
- 树莓派使用触摸开关上手初体验