optimize execution time

WHAT HAPPENS IS THAT THE EXE FILE GENERATED FOR SOLVING THE PROBLEMS DOESNT PRODUCE ANY RESULT AT ALL ITS JUST THE BLANK BLACK SCREEN. DUE TO LARGE INPUTS WHICH I THINK SHOULD BE FAIRLY COMPUTABLE
Can u suggest some method to optimize code

for example #include<iostream>
using namespace std;
int main ()
{for(long g=50;g<1E7;++g)
{int d=2;
long p=((g*(g+1))/2);
for(long c=2;c<p;++c)
if(!(p%c))
++d;
if (d>=499)
{cout<<g<<endl<<d;int a;cin>>a;
}
}return 0;
}
For indentation and semplification's sake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
using namespace std;
int main ()
{
    for(long g=50; g < 10000000; ++g)
    {
        int d=2;
        long p= (g*(g+1))/2;
        for(long c=2; c<p; ++c)
        {
            if(!(p%c))
                ++d;
        }
        if (d >= 499)
        {
            cout<<g<<endl<<d;
            int a;
            cin>>a;
        }
    }
    return 0;
}


Also, the best 'd' result is 320, gotten from 'g' being 2079.
Probably the reason why you don't get in the 'd >= 499' part.
Still looking for best numbers.
Reached 'd' 480 with 'g' 5984. I'm near.
EssGeEich wrote:
Reached 'd' 480 with 'g' 5984. I'm near.


Mmmmmm
Nothing better, it took so long I stopped.
Last edited on
Topic archived. No new replies allowed.