zoukankan      html  css  js  c++  java
  • Gym-100923I-Por Costel and the Pairs(数学,思维)

    链接:

    https://vjudge.net/problem/Gym-100923I

    题意:

    We don't know how Por Costel the pig arrived at FMI's dance party. All we know is that he did.

    The dance floor is hot because Por Costel broke the air conditioner. On the dance floor, the boys and girls are clumsy. There are boys at the party. The -th one has clumsiness level . There ale also girls at the party. The -th girl has clumsiness level as well. Por Costel finds that a pair of a boy and a girl can dance only if the product of their clumsiness levels is at most , i.e. girl clumsiness level * boy clumsiness level . Por Costel thinks that a sack of oats with a slice of leek could make a better dancing pair than the people at this party. Nonetheless, he would like to find out how many pairs (boy, girl) can dance. The input will contain the number representing the number of tests. The next lines will contain the number .

    思路;

    因为是男和女都能选,优化到sqrt(n),每次n/i算两次,但是前i个用过了,最后在加上当前对应的.

    代码:

    #include <iostream>
    #include <memory.h>
    #include <string>
    #include <istream>
    #include <sstream>
    #include <vector>
    #include <stack>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <set>
    #include <iterator>
    #include <cstring>
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 1e6+10;
    const int MOD = 1e9+7;
    
    LL n;
    
    int main()
    {
        freopen("perechi3.in","r",stdin);
        freopen("perechi3.out","w",stdout);
        int t;
        cin >> t;
        while (t--)
        {
            LL res = 0;
            cin >> n;
            for (LL i = 1;i*i <= n;i++)
                res += 2*(n/i-i)+1;
            cout << res << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    哥也能写KMP了——实现strstr()
    面试归来,感觉无望,下次再战
    Pow(x, n)
    Length of Last Word
    后缀数组应用
    2倍倍增算法构造后缀数组
    跳台阶问题
    求无序数组中第二大的数--快速选择
    单源最短路径问题
    全局下的isFinite
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11369681.html
Copyright © 2011-2022 走看看