Problem 012

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
cheesecakenl
Posts: 6
Joined: Sat Jul 09, 2011 7:32 pm

Re: Problem 012

Post by cheesecakenl »

Hi,

I am having a bit of trouble solving this one. Here is some pseudo code using the 1+2+3=6=3*4/2 principle. Atleast I think but
it keeps getting me the wrong answer.

I guess there is something wrong with my assumption "if the n/2 and n+1 values are co-prime they will have the same number of dividers and you can just multiply them to get the number of dividers for the corresponding triangle number n(n+1)/2 " :)

Code: Select all

n = 1
while div < 501
	val1 = n/2
	val2 = n+1

	if coprime(val1,val2)
		nr = getNumberOfDiv(val1)
		div = nr * nr 
	
	n++
Results:
Triangle number: 258840
Divisors: 576 (24x24)
User avatar
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 10:43 am
Location: Netherlands

Re: Problem 012

Post by Lord_Farin »

What about n = 24? 12 has more divisors than 25 (6 vs. 3). Still, you are not too far off. Try to think in prime factorisations.
Image
cheesecakenl
Posts: 6
Joined: Sat Jul 09, 2011 7:32 pm

Re: Problem 012

Post by cheesecakenl »

I solved it. According to the pdf there is some optimization available in calculating the number of divisors.
Expand
D(28) = 22 * 71 = (2+1) * (1+1) = 3 * 2 = 6
Using the sieve I can get a list of all prime factors for 28. Except I don't know how to get from D(28) to the (2+1) * (1+1) part.
Can anyone PM this ?
User avatar
rayfil
Administrator
Posts: 1412
Joined: Sun Mar 26, 2006 5:30 am
Location: Quebec, Canada
Contact:

Re: Problem 012

Post by rayfil »

PM sent.
When you assume something, you risk being wrong half the time.
FF_Daniel
Posts: 1
Joined: Tue Aug 02, 2011 9:56 am

Re: Problem 012

Post by FF_Daniel »

Can somebody please send me a pm with the area of the result? A diffrence of one million is no problem!
dufoli
Posts: 1
Joined: Wed Aug 10, 2011 4:48 pm

Re: Problem 012

Post by dufoli »

Hello,

I have produce a code in python but it seems that I do a mistake because I do not get result ok message.

EDIT: ok found small mistake
kavcict
Posts: 2
Joined: Sat Nov 12, 2011 5:35 pm

Re: Problem 012

Post by kavcict »

Hi,

I'm currently having a speed problem with my Python code. My code has three different functions. The first one gives me the triangle sum of a given number, the second functions gives me how many divisors this numbers has, the last one solves the problem. The code works fine with small numbers, but with numbers greater the 100 the code slows down. I've read all post in this topic, but i can't find a solution to my problem.

Can anybody help me?
Image
User avatar
PurpleBlu3s
Posts: 75
Joined: Mon Sep 19, 2011 6:49 pm

Re: Problem 012

Post by PurpleBlu3s »

kavcict wrote:Hi,

I'm currently having a speed problem with my Python code. My code has three different functions. The first one gives me the triangle sum of a given number, the second functions gives me how many divisors this numbers has, the last one solves the problem. The code works fine with small numbers, but with numbers greater the 100 the code slows down. I've read all post in this topic, but i can't find a solution to my problem.

Can anybody help me?
It sounds like you need to look at your algorithm for getting divisors and try and see how you can make it more efficient.
Image
kavcict
Posts: 2
Joined: Sat Nov 12, 2011 5:35 pm

Re: Problem 012

Post by kavcict »

PurpleBlu3s wrote:
It sounds like you need to look at your algorithm for getting divisors and try and see how you can make it more efficient.

I've check the divisor algorithm and found a solution to my problem :) I will try to tweak the code to go a little bit faster.

Python
Mac OS X Lion 2.66 GHz Intel Core 2 Duo, 15sec
Windows 7 2.33GHz Intel Core 2 Quad, 8 sec
Image
extremeblueness
Posts: 6
Joined: Wed Aug 14, 2013 12:38 am

Re: Problem 012

Post by extremeblueness »

Okay. So here's my problem:

After fixing my program's speed, I got the number within half a minute.

However, when I input the number, it says that its not the answer.

Properties of my number:

-576 divisors
-index of more than 16000

Also, I checked my data with a triangle number calculator and a divisors calculator. My data was confirmed.

Any ideas as to why its not accepting my answer?
Image
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 012

Post by hk »

extremeblueness wrote:Okay. So here's my problem:

After fixing my program's speed, I got the number within half a minute.

However, when I input the number, it says that its not the answer.

Properties of my number:

-576 divisors
-index of more than 16000

Also, I checked my data with a triangle number calculator and a divisors calculator. My data was confirmed.

Any ideas as to why its not accepting my answer?
the index is too high.
Image
War ruins the life and health of untold numbers of innocent children.
extremeblueness
Posts: 6
Joined: Wed Aug 14, 2013 12:38 am

Re: Problem 012

Post by extremeblueness »

In that case, I'm left with this question: why isn't my program calculating correctly for one or more numbers? The triangle numbers are right, so there must be something wrong with the divisors method. But I can't figure out what it might be. The thing is, its a brute force method, so it SHOULDN'T calculate incorrectly when it calculates correctly for the vast majority of numbers.

edit: never mind. I was just randomly disabling parts of my code, and for some reason, fixed it when i took something out. I still can't figure out why disabling that part worked.
Image
youssef
Posts: 2
Joined: Thu Aug 14, 2014 12:48 am

Re: Problem 012

Post by youssef »

Hi, i'm not really stuck , but i was trying to make a programm to calculate the number of factors of a given integer n, but it doesn't work : it seems to enter an infinite loop or something like that: I was hoping you gus could help me figure out what is wrong with my programm, so here is the code (don't be harsh on me, i've only started learning python two days ago):

Edit: Code removed by moderator -- please read the big red box at the top of the forum.

PS: English isn't my native language, so I 'm sorry for the mistakes
thundre
Posts: 356
Joined: Sun Mar 27, 2011 10:01 am

Re: Problem 012

Post by thundre »

If you have two while loops nested, the outer condition is only checked when the inner loop exits. In your case, your inner condition will never be false, so the inner loop becomes infinite.

I also question whether you even need two nested loops for your purpose. I think one would be enough.
Image
thefloppyfish
Posts: 3
Joined: Thu May 04, 2017 5:11 pm

Re: Problem 012

Post by thefloppyfish »

Im really confused, am I supposed to be finding unique divisors as shown in the example or can one divisor be used multiple times. For example for 36 would it have 9 divisors [1, 2, 3, 4, 6, 9, 12, 18, 36] or 12 divisors [1, 2^2, 3^2, 4, 6^2, 9, 12, 18, 36]?
MuthuVeerappanR
Posts: 539
Joined: Sun Mar 22, 2015 2:30 pm
Location: India
Contact:

Re: Problem 012

Post by MuthuVeerappanR »

36 would have 9 divisors..
Image
It is not knowledge, but the act of learning, not possession but the act of getting there, which grants the greatest enjoyment.
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 012

Post by hk »

If you're still stuck with this problem you might look at :number of divisors or number of divisors
Image
War ruins the life and health of untold numbers of innocent children.
sriramrajan
Posts: 4
Joined: Wed Aug 29, 2018 8:22 am

Re: Problem 012

Post by sriramrajan »

My answer has 112 divisors / factors and is the first one in the series but was declared wrong.

The previous one with 28 factors is 73536 is the 383rd in the list:

73536 , Factors: [1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 192, 383, 766, 1149, 1532, 2298, 3064, 4596, 6128, 9192, 12256, 18384, 24512, 36768, 73536] , #Factors: 28

What does prime factors have to do with this problem? Here's my program listing the first 10 triangular numbers:
1 , Factors: [1] , #Factors: 1
3 , Factors: [1, 3] , #Factors: 2
6 , Factors: [1, 2, 3, 6] , #Factors: 4
10 , Factors: [1, 2, 5, 10] , #Factors: 4
15 , Factors: [1, 3, 5, 15] , #Factors: 4
21 , Factors: [1, 3, 7, 21] , #Factors: 4
28 , Factors: [1, 2, 4, 7, 14, 28] , #Factors: 6
36 , Factors: [1, 2, 3, 4, 6, 9, 12, 18, 36] , #Factors: 9
45 , Factors: [1, 3, 5, 9, 15, 45] , #Factors: 6
55 , Factors: [1, 5, 11, 55] , #Factors: 4
....

The maximum value is for 437580 with 144 factors and is the 944th triangle number among the first 1000 triangle numbers

Any idea if I have missed anything here ?
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem 012

Post by jaap »

sriramrajan wrote: Fri Sep 07, 2018 10:04 amMy answer has 112 divisors / factors and is the first one in the series but was declared wrong.
The question is not asking for the first one with 112 divisors, but for
... the first triangle number to have over five hundred divisors?
sriramrajan
Posts: 4
Joined: Wed Aug 29, 2018 8:22 am

Re: Problem 012

Post by sriramrajan »

Thanks. My bad, I read it as a hundred divisors.. missing the five!!! Sorry.
Post Reply