Monday, October 31, 2011

[UVa] 10830 - A New Function

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>

typedef unsigned long long ull;
typedef long long xll;
typedef long double ld;

using namespace std;
ull sumfind(ull a, ull n)
{
    return ((n*(n+1)/2) - (a*(a-1)/2));
}
ull csod(ull n)
{
    ull root = (ull)sqrt((double)n), i, j;
    ull lim, sum=0;

    for (i=2 ; i<=root ; i++)
    {
        lim = n/i;
        sum += (sumfind(i+1,lim) + (i*(lim-i+1)));
    }

    return sum;
}

int main()
{
    ull n, sum=0, kase=1;

    while (cin >> n && n)
    {
        cout << "Case " << kase++ << ": " << csod(n) << endl;
    }
    return 0;

}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...