HDU 2608 底数优化分块 暴力

T(n) as the sum of all numbers which are positive integers can divied n. and S(n) = T(1) + T(2) + T(3)…..+T(n). 

定义T(n)为n的因子和($\sigma(n)$),求$S(n) % 2=\sum\limits_{i=1}^{n}T(i) mod 2$,n<=1e9。

你总是说找规律,可是找规律已经累了。找规律不想对付数论题,它想做水题(这个就是呀),你考虑过它的感受吗?没有!你只关心你自己。找规律天下第一!(吃面)

$ans=\sum\limits_{i=1}^{n}\sum\limits_{d|i}d=\sum\limits_{d}^{n}\lfloor\frac{n}{d}\rfloor d$

底数优化,重复项是等差数列的和(不用我说吧)..复杂度$O(\sqrt{n})$

 

/** @Date    : 2017-09-20 23:16:50
  * @FileName: HDU 2608 分块 容斥.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		LL n;
		scanf("%lld", &n);
		LL ans = 0;
		for(LL i = 1, j; i <= n; i = j + 1)
		{
			cout << i << endl;
			j = (n /(n / i));
			ans += (n / i) * (i + j) * (j - i + 1) / 2;
			cout << ans << endl;
		}
		printf("%lld\n", ans);
	}
    return 0;
}
posted @ 2017-09-21 00:46  Lweleth  阅读(170)  评论(0编辑  收藏  举报