Quick question - [RESOLVED]
Hi everyone, I'm trying out these programming challenges at www.osix.net, and I'm already stuck on... *sigh* Challenge 2.
Well here is the question:
Quote:
13 * 2 = 26
x * y = 133745639
Write a program which can work out what the possible values of x and y are.
For this exercise, x and y cannot be 1 and are both whole positive numbers.
Once you have established values for x and y, add them together and submit your answer below.
I read somewhere that people have made brute forcer type programs, so I thought I'd have a go at it.
I came up with this but it doesn't seem to be working, Not that there's any compile errors, but it just seems to be getting stuck somewhere (I tested it on smaller numbers). If anyone can see where I'm going wrong or provide any help that'd be great.
Code:
#include <iostream>
using namespace std;
int main()
{
int x = 2, y = 2;
cout << "The brute forcer is now attempting to find the factors\nThis may take some time...";
while(x * y != 133745639)
{
for(x=2; x==133745639; x++)
{
for(y=2; y==133745639; y++)
{
}
cout << "\n";
cout << x << " * " << y << " = " << x*y;
}
}
cout << "\n-------------------------------\nThe brute forcer has found the factors of 133745639";
cout << "\nThe factors are: " << x << " and " << y;
cout << "\n\nThe sum of these numbers is " << x + y;
}
Thanks in advance :)