Testing to prove or disprove a theorem with c++

I attempting to test a discrete math theory (for a class) the object of this lesson is determine if we should attempt to prove or disprove the theory by writing a program that runs numbers on it so to speak. If someone could look at my work and let me know if you think I am on the right track or not.


The theorem
http://i.imgur.com/hscZ7yd.png

The code I have written ( I think correctly - this is what I want feedback on )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
bool __theorem__1();

mpz_class is_odd ( mpz_class input );
mpz_class const RANGEMAX = 10;

int main ( int argc, const char * argv[] )
{
    __theorem__1();
    return 0;
}

mpz_class is_odd ( mpz_class input )
{
    return input % 2;
}

bool __theorem__1()
{
    // set result to 0
    mpz_class result = 0;
    // for all m
    for ( mpz_class m = 0 ; m < RANGEMAX; m++ )
    {
        // if m is odd
        if ( is_odd ( m ) )
        {
            // set k to 0, and n to 1,
            // increment loop until k is greater or equal to m-1
            mpz_class k = 0 , n = 1;
            for ( ; k >= m - 1; k++, n++ )
            {
                result += ( n + k );
            }
            // if m does not a multiple of m then print counter example. 
            if ( ( result % m ) != 0 )
            {
                cout << "found counter example with k = : " << k << "and n " << n << endl;
            }
            else
            {
                cout << "No counter example found " << endl;
            }
        }
    }
    // this is just here for now. I will update bool logic later. 
    return  true;
}
Last edited on
Topic archived. No new replies allowed.