• 华中农业大学预赛 B Handing Out Candies 余数的和


    Problem B: Handing Out Candies

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 258  Solved: 19
    [Submit][Status][Web Board]

    Description

        After the 40th ACM-ICPC, Diao Yang is thinking about finding a girlfriend because he feels very lonely when doing ACM all the time. But because of his philandering, he finally decided to find N girlfriends. To achieve his goal, he wanted to find one girlfriend every day for N days continue. That is to say, at the ith day, he will have i girlfriends exactly.

        In order to make his N girlfriends happy, he decided to buy candies everyday for N days continue. Every day all of his girlfriends can get candies, and he will give each of them the same amount of candies and the amount will be as much as possible. Then if there are some candies left, he will eat them by himself.

        Now the problem is, Diao Yang want to know how many candies he can eat total by himself after N days continue.

    Input

        The first line contains an integer T, indicating the total number of test cases. Each test case is a line with two integers N 15N" style="box-sizing: border-box; 9pt; height: 15.75pt;"> and M ( 151鈮?/m:t>N&lolt;231" style="box-sizing: border-box; 63.75pt; height: 15.75pt;">  ,  150鈮?/m:t>M&lolt;231" style="box-sizing: border-box; 65.25pt; height: 15.75pt;"> ).

    Output

        For each test case, output the answer in one line.

    Sample Input

    2
    5 7
    6 4

    Sample Output

    7
    9
        N
    题意:求∑ ( m%i);
        i=1
    思路:会发现M对一个数取模成等差数列;
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define inf 999999999
    #define esp 0.00000000001
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    int main()
    {
        ll x,y,z,i,t;
        scanf("%lld",&x);
        while(x--)
        {
            scanf("%lld%lld",&y,&z);
            ll ans=max(y-z,0LL)*z;
            ll huan=min(y,z);
            for(i=2;i<=huan;i++)
            {
                if(z%i!=0)
                {
                    ll d=z/i;
                    ll maxx=min((z%i)/d+1,huan-i+1);
                    d=-d;
                    ans+=(z%i)*maxx+(maxx*(maxx-1)/2)*d;
                    i+=maxx-1;
                }
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    如何将程序添加到系统服务实现开机自启动
    ASP.NET速度优化
    layer官方演示与讲解(jQuery弹出层插件)
    SQLSERVER排查CPU占用高的情况
    解决FlexPaper分页分段加载问题(转)
    SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10.50.1600
    Virtualbox中win7虚拟机中U盘不可用问题的解决
    解决:对COM 组件的调用返回了错误 HRESULT E_FAIL
    google chrome插件开发,自己动手,丰衣足食
    WebKit.net最简单使用方法
  • 原文地址:https://www.cnblogs.com/jhz033/p/5492901.html
Copyright © 2020-2023  润新知