Formula for dividing each individual member in a summation

Example: ! [math] http://mathurl.com/83cpbet.png

When division is applied as a whole, the result:

http://mathurl.com/79p3hoh

The summation formula is given by the expression: summation

The above can be easily calculated in O (1) using the summation rules.

But when it is applied to each term individually (truncation after the decimal point in quotient) = 0 + 1 + 1 + 2 + 3 + 3 + 4 + 5 = 19. [using normal int/ intdivision in C]

The above method requires O (N), since the summation rules can NOT be applied.

I understand that this is due to a loss of accuracy when division is applied to each member, and not to the last. But this is what I need. [In the example above, 19 is the solution, not 21]

, , ?

+3
6

, :

0 + (1 + 1 + 2) + (3 + 3 + 4) + 5

3:

0 + (3 + 3 + 6) + (9 + 9 + 12) + 15

(1 +... + 15)/3:

1 + (3 + 5 + 7) + (9 + 11 + 13) + 15

, , , 3 3 1 . , :

(0 + 3 + 3) + (6 + 9 + 9) + 12 + 15
(1 + 3 + 5) + (7 + 9 + 11) + 13 + 15

0 + 3 + (3 + 6 + 9) + (9 + 12 + 15)
1 + 3 + (5 + 7 + 9) + (11 + 13 + 15)

, * 3 (1 +... + 15)/3 .

: n 2 n - :

1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 = 2 8= 64

8 64, 56 3, 18.6 (6). 19, n ( ) 3.

, (n 2 - n)/3, 1 .

:

(n * n-n + 1)/3 .

(), :

(8 * 8-8 + 1)/3 = 57/3 = 19

+3

: , .

( , ):

: , int- int- .

:

, , .

, , .

, .

, 1/3, 0, 2/3.

3, , , (, ).

, : (n ^ 2)/3 - (n/3)

n * n/3 - , , 3 1, n/3.

+1

1+1 + 2 + 3+3 + 4 + 5+5 + 6 + 7+7 + 8 + 9+9 + 10 + ...

, - . n n*(n+1)/2, n , n n*n.

, , ...

+1

, , n s: 1, 2, 4, 7, 10, 14, 19, 24, 30, 36...

- ™ (OEIS ™) A007980 , . a (n) = ceil ((n + 1) * (n + 2)/3).

(0) = 1, a (1) = 2, a (6) = 19, , 2: sum (1,8) = a (8-2).

+1
Σ((2i+1)/3) where i =0 to n-1 and Σ((2i+1)/3) = n*n/3
0
#include <stdio.h>

typedef struct fraction {
    int n;//numerator
    int d;//denominator
} Fraction;

int gcd(int x, int y){
    x = (x < 0)? -x : x;
    y = (y < 0)? -y : y;
    while(y){
        int wk;
        wk = x % y;
        x = y;
        y = wk;
    }

    return x;
}

Fraction rcd(Fraction x){
    int gcm;
    gcm = gcd(x.n, x.d);
    x.n /= gcm;
    x.d /= gcm;
    return x;
}

Fraction add(Fraction x, Fraction y){
    x.n = y.d*x.n + x.d*y.n;
    x.d = x.d*y.d;
    return rcd(x);
}

int main(void){
    Fraction sum = {0,1};
    int n;

    for(n=1;n<=8;++n){
        Fraction x = { 2*n-1, 3 };
        sum = add(sum, x);
    }
    printf("%d/%d=",sum.n,sum.d);
    printf("%d",sum.n/sum.d);

    return 0;
}
0

All Articles