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?

Recommended Answers

All 4 Replies

>>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);

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...

;)

Oh my god! :-O

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.