zoukankan      html  css  js  c++  java
  • Codeforces1062D. Fun with Integers(埃氏筛)

    题目链接:传送门

    题目:

    D. Fun with Integers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    
    You are given a positive integer n
    greater or equal to 2. For every pair of integers a and b (2≤|a|,|b|≤n), you can transform a into b if and only if there exists an integer x such that 1<|x| and (a⋅x=b or b⋅x=a), where |x| denotes the absolute value of x
    
    .
    
    After such a transformation, your score increases by |x|
    points and you are not allowed to transform a into b nor b into a
    
    anymore.
    
    Initially, you have a score of 0
    
    . You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
    Input
    
    A single line contains a single integer n
    (2≤n≤100000
    
    ) — the given integer described above.
    Output
    
    Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0
    
    .
    Examples
    Input
    Copy
    
    4
    
    Output
    Copy
    
    8
    
    Input
    Copy
    
    6
    
    Output
    Copy
    
    28
    
    Input
    Copy
    
    2
    
    Output
    Copy
    
    0
    
    Note
    
    In the first example, the transformations are 24→(−2)→(−4)→2
    
    .
    
    In the third example, it is impossible to perform even a single transformation.
    View Code

    思路:

      如果一对数a,b可以通过x转换得到分数,那么a→b→-a→-b→a总共可以得到4*|x|的分数。

      不妨只考虑0 < a < b,0 < x的情况,把结果乘上4就好了。

      此时只能有a*x = b,即b为a的整数倍。对于给定的a,x可以取[2, n/a]范围内的所有值,为一个等差数列。用求和公式计算即可。

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        ll n;
        cin >> n;
        ll ans = 0;
        for (ll i = 2; i <= n/2; i++) {
            ll cnt = n/i;
            ans += 4*(2+cnt)*(cnt-1)/2;
        }
        cout << ans << endl;
        return 0;
    }
    View Code
  • 相关阅读:
    九月二十日
    九月十九日
    九月十八日
    九月十七日
    九月十六日
    大三第一周学习后的感悟及本学期计划
    阅读笔记09梦断代码
    阅读笔记08-梦断代码
    对搜狗现如今的用法进行评述
    寻找水王
  • 原文地址:https://www.cnblogs.com/Lubixiaosi-Zhaocao/p/9964814.html
Copyright © 2011-2022 走看看