LightOJ 1098 - A New Function

Dec 3, 2015

Problems: LightOJ 1098 - A New Function
Explain:
The function  SOD(n)  (sum of divisors) is defined as the summation of all the actual divisors of an integer number n.The function CSOD(n) (cumulative SOD) of an integer n, is defined as below:

 
Let P =  1 - 25

Total: 173


Given Number P = 25, i = 2 , j= P/i = 12
From above calculation, we can find out two relations
First Relation
2+3+4+5+6+7+8+9+10+11+12
= 1+2+3+4+5+6+7+8+9+10+11+12-1 
= j*(j+1)/2 - (i-1)*(i-1+1)/2  
= j*(j+1)/2 - (i-1)*(i)/2
= (j^2+j - i^2 + i)/2
= ((j-i)(j+i)+(j+i))/2
= ((j+i)(j-i+1))/2  (General Form)
= (14 * 11 )/2 = 77

Second Relation
2x10 = i*(j-i)  (General Form)
     = 20

Again
 i  = 3 ,  j = P/i = 8

First Relation
3+4+5+6+7+8
= (1+2+3+4+5+6+7+8) - (1+2)
= (j*(j+1)/2 - (i-1)*(i-1+1)/2
= ((j+i)(j-i+1))/2  (General Form)
= (11 * 6 )/2 = 33

Second Relation
3x5 = i*(j-i)
    = 15

Again
 i  = 4 ,  j = P/i = 6

First Relation
4+5+6
= (1+2+3+4+5+6) - (1+2+3)
= (j*(j+1)/2 - (i-1)*(i-1+1)/2
= ((j+i)(j-i+1))/2  (General Form)
= (10 * 3 )/2 = 15

Second Relation
4x2 = i*(j-i)
    = 8

Again
 i  = 5 ,  j = P/i = 5

First Relation
5
= (1+2+3+4+5) - (1+2+3+4)
= (j*(j+1)/2 - (i-1)*(i-1+1)/2
= ((j+i)(j-i+1))/2  (General Form)
= (10 * 1 )/2 = 5

Second Relation
5x0 = i*(j-i)
    = 0

SUM = 77+20+33+15+15+8+5+0 = 173


Code:
-------



#include <stdio.h>
typedef long long LL;

void solve() {
  LL n,ans = 0;
  LL i,j;

  scanf("%lld",&n);
  for (i = 2; i * i <= n; ++i) {
    j = n / i;
    ans += (i + j) * (j - i + 1) / 2;
    ans += i * (j - i);
  }
  printf("%lld\n", ans);
}

int main() {
  int tc;
  scanf("%d",&tc);
  for (int i = 0; i < tc; ++i) {
    printf("Case %d: ", i + 1);
    solve();
  }
  return 0;
}

1 comment:

  1. Want to learn more about this.
    please give references.
    Thank you.

    ReplyDelete