Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Euler

Name: Anonymous 2008-11-15 23:13

I'm working on Euler problem number 12. I've got the following:

//cut out my includes
bool IsPrime(int num)
{
    bool prime = true;
    int number2 =(int) floor (sqrt ((long double)num));
    for ( int j = 2; j <= number2; j++){
        if ( num!=j && num % j == 0 ){     
            prime = false;
            break;
        }
    }
    return prime;
}

int NumDivisors(__int64 num)
{
    int count = 0;
    if(!IsPrime(num))
    {
        __int64 number2 = num/2;
        for ( __int64 j = 2; j <= number2; j++){
            if ( num % j == 0 ){     
                count++;
            }
        }
    }
    return count;
}

int _tmain(int argc, _TCHAR* argv[])
{
    bool found = false;
    __int64 num = 1;
    __int64 maxdiv = 0;
    while(!found)
    {
        __int64 trinum = 0;
        for(int i = 0;i<=num;++i) trinum += i;
        int div = NumDivisors(trinum);
        if(div>maxdiv) maxdiv = div;
        if(div>500) found = true;
        if(!found) ++num;
    }
    return 0;
}

The problem is, NumDivisors is horribly inefficient. I mean 30 minutes at 2.5ghz and I'm only on num=9219 with a maxdiv of 478. Any suggestions?

Name: Anonymous 2008-11-15 23:30

There's a faster algorithm to get the number of divisors. You only have to check up to the sqrt of the number, but for every divisor in that group, theres actually two real divisors: the number itself, and num/divisor, or something to that effect.

Name: Anonymous 2008-11-15 23:31

Also what the fuck is with your main function man it is FUCKED up.

Name: Anonymous 2008-11-15 23:38

Thanks, 2!

Name: Anonymous 2008-11-16 1:09

Jesus Christ OP's main is an abomination. What is this, some sort of Microsoft weenie standard or something? Tmain? Tchar?

Name: Anonymous 2008-11-16 2:19

>>5
Tgirl?

Name: polymorph !uKEFW4r7WU 2008-11-16 3:08

>>6
Tgirl here, we're not microsoft

Name: Anonymous 2008-11-16 3:44

>>7
That's all right then, Audrey.

Name: Anonymous 2008-11-16 6:21

>>2 is indeed correct.

But I'll also give you a hint, because this optimisation is truly beautiful. There's a very neat trick you can do that exploits properties of the divisor function on triangular numbers. That should be enough of a hint.

I feel kind of good about it :-)

Name: Anonymous 2008-11-16 13:11

This is not how it’s done
you copy−paster

Name: Anonymous 2008-11-16 14:17

Hey you make it sound like there are GIRLS around here please get them out this is a secret treehouse.

Name: Anonymous 2008-11-16 14:32

>>11
These aren't naturally-occurring girls.  They're perfectly safe.

Name: Anonymous 2008-11-16 15:04

Some of the most competant programmers I know are female.

Name: Anonymous 2008-11-16 15:07

>>13
Some of the most competent spellers I know are female.

Name: Anonymous 2008-11-16 15:37

>>14
Some of the most competent Web 2.0 programmers I know are female.

Name: Anonymous 2008-11-16 15:50

Some of the most competent females I know are males.

Name: Anonymous 2008-11-16 16:02

>>13,15
traps don't count.

Name: Anonymous 2008-11-16 16:23

Some of the most competent Leah Culvers I know are Pythonistas.

Name: Anonymous 2008-11-16 16:26

I don't know any female competent programmers. But then again, I don't know any male competent programmers either.

Name: Anonymous 2008-11-16 16:28

>>19
Wanna trade MSNs?

Name: Anonymous 2008-11-16 16:31

>>20
Why on earth would anyone use MSN?

Name: Anonymous 2008-11-16 17:27

>>21
I am a competent programmer. Let's chat.

Name: Anonymous 2008-11-16 17:28

>>22
If you were a competent programmer, you'd use XMPP and IRC.

Name: Anonymous 2008-11-16 20:10

If you were a competent programmer, you'd use Usenet and have your secretary print out your e-mails once a year.

Name: Anonymous 2008-11-16 20:50

If you were a competent programmer, you'd snail mail me your secret manuscripts of programming gems carefully crafted by Tibetan monks since you have reached Satori.

Name: Anonymous 2008-11-16 22:13

If you were an EXPERT PROGRAMMER, you'd [spoiler][sub][sup][code]haxmyanus[code][/sup][/sub][/spoiler].

Name: Anonymous 2008-11-16 22:27

Srsly gays...

If you were a competent programmer, you would send and read UDP-packets like god intended.

Name: EXPERT PROGRAMMER 2008-11-16 22:48

% nc -vulp 36666 to set up.
% echo "Msg" > /dev/udp/hostname/36666 to send.

Name: Anonymous 2008-11-17 0:04

If you were a competent programmer you wouldn't be on a programming bbs

Name: Anonymous 2008-11-17 2:43

>>29
Ah, but by posting that message on this board you are admitting that you, yourself, are an incompetent programmer.
And so life imitates art.

Name: Anonymous 2008-11-17 2:46

>>30
And so your wife is dating bart.

Name: Anonymous 2008-11-17 9:54

>>30

Stunning, really. Almost as deep as RANDALL

Name: Anonymous 2010-12-17 1:27

Xarn is a bad boyfriend

Name: Anonymous 2011-02-03 0:09

Name: Anonymous 2011-02-04 14:15


Don't change these.
Name: Email:
Entire Thread Thread List