factoring

Started by
14 comments, last by vaneger 20 years ago
quote:Original post by vaneger
actually i goofed i dont need numbers that multiply to get a producti need numbers that add to get a number how can i find that? such as 2 + 5 = 7 or 3 + 4 = 7 etc


Assuming that you are dealing with integers: start with the number, subtract one. The result and 1 is one set.

Then subtract 2, the result and 2 is another set. And so on and so forth.

BTW.

I dont't think the OP asked for prime factors anyways.




[edited by - yspotua on April 3, 2004 8:52:19 PM]
Advertisement
Aprosenf: Hm?
>> 216
2 2 2 3 3 3

Looks like it works to me. What number would break it?

[twitter]warrenm[/twitter]

quote:Original post by vaneger
actually i goofed i dont need numbers that multiply to get a producti need numbers that add to get a number how can i find that? such as 2 + 5 = 7 or 3 + 4 = 7 etc


There are an infinite number solutions to that problem, you need to add some constraints.


You have to remember that you''re unique, just like everybody else.
If at first you don't succeed, redefine success.
no there are 8 solutions to that problem i believe
0+7 1+6 2+5 3+4 7+0 6+1 5+2 4+3 or only 4 if order is limited.
No, he was right to say there are infinite answers. For example, 100 + (-93) = 7. Now, if you add some constraints like he said...
Turring Machines are better than C++ any day ^_~
whole positive numbers less than or equal to the given number
the number of additive pairs is equal to (n+1)/2 with the above example of 7 the number of pairs is 4 (07,16,25,34) not counting reverses. i currently have this code
struct pr{	int first;	int second;};vector<pr> pairs;void set_pairs(int n){	int q = (n+1) / 2;	pairs.resize(q)	for(int i = 0; i < q;i++)	{		pairs[i].first = n -  i;		pairs[i].second = n - (n-i); 	}}

but im not sure if set_pairs can be made faster or not.

This topic is closed to new replies.

Advertisement