0
int MAX_NUM = 600851475143;
	int max = 0;

	vector <int> ints;
	for(int i = 1; i <= MAX_NUM; ++i)
		if((int)MAX_NUM % i == 0)
			ints.push_back(i);

	cout << "size = " << ints.size();

I get 0. Something is wrong. I get 2 warnings:
warning C4305: 'initializing' : truncation from '__int64' to 'int'
warning C4309: 'initializing' : truncation of constant value

So I did this:

__int64 MAX_NUM = 600851475143;

	vector <__int64> ints;
	for(__int64 i = 1; i <= MAX_NUM; ++i)
		if((__int64)MAX_NUM % i == 0)
			ints.push_back(i);

	cout << "size = " << ints.size();

I don't get anything. I get an empty character "". Then cin.get() follows but it doesn't work.
How can I solve this?

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Alex Edwards
0

>>if((__int64)MAX_NUM % i == 0)
That will result in only ONE int being pushed back onto the vector. You could save alot of processing time by just this: ints.push_back(MAX_NUM);

0

Alas, modern computers are very fast beastes but not so fast as you wish...

Think: you define 600851475143 loops (~10^12 times). I'm too lazy to profile your code but I'm sure that your (and mine) computer is not capable to perform more than 10^8 (or near) this loop bodies per second. So press enter then wait... for 3 (or 30) hours...

;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.