zoukankan      html  css  js  c++  java
  • UVA 11526 H(n) (数论)

    题意:输入n(在32位带符号整数范围内),计算下面C++函数的返回值。

    分析:合并同类项加速一下即可。

    假设n为100,则n/34=2,那么通过n/2=50,可知道34到50的结果都是2,以此加速。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-8;
    inline int dcmp(double a, double b) {
        if(fabs(a - b) < eps)  return 0;
        return a < b ? -1 : 1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 16384 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int main(){
        int T;
        scanf("%d", &T);
        while(T--){
            LL n;
            scanf("%lld", &n);
            LL ans = 0;
            for(LL i = 1; i <= n; ++i){
                LL tmp = n / i;
                LL et = n / tmp;
                ans += (et - i + 1) * tmp;
                i = et;
            }
            printf("%lld\n", ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    《代码大全》阅读心得一
    vi列模式
    以指定的概率/机会获取元素
    自用VIM配置
    优雅的Javascript
    关于遮罩层
    CSS3属性BorderRadius详解[圆角]
    CSS3属性boxshadow详解[盒子阴影]
    CSS3文字特效
    Css3 Animation详解
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6382342.html
Copyright © 2011-2022 走看看