zoukankan      html  css  js  c++  java
  • 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=sumlimits_{i=1}^{n}T(i) mod 2$,n<=1e9。

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

    $ans=sumlimits_{i=1}^{n}sumlimits_{d|i}d=sumlimits_{d}^{n}lfloorfrac{n}{d} floor 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
    ", ans);
    	}
        return 0;
    }
    
  • 相关阅读:
    面向对象、构造函数的区别
    写一个function,清除字符串前后的空格。(兼容所有浏览器)
    两个DIV高度自适应方法(左右两个DIV高度一样)
    js数组去重
    input框处理删除小图标的功能
    查找显示高亮
    JSON.parse()和JSON.stringify()
    jquery封装
    怎么理解HTML语义化
    html5语义化标签
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7566161.html
Copyright © 2011-2022 走看看