can long long store 12 digit numbers.
Its showing in my comp that limit of long long is 9223372036854775807, but then it's showing too large when i declare it like this:
long long num;
i don't want to store in array.
My seniors told that long long will do but i am having trouble.
please help.

a) post what you actually tried, not a description.
b) post your actual error messages
c) tell us what your OS/Compiler is.

From this thread I would suggest you to use: [B]unsigned long long[/B] :)

>can long long store 12 digit numbers.
Depends on what your compiler is...

this is my code. Problem as described above.
We have to find largest prime factor of a number.

#include<iostream>
using namespace std;
int main()
{
	
	long long num=600851475143,large,k,i;
	
	for(i=2;;++i)
	{  k=i;
		if(num%i==0)
		{	num/=i;
			i=k-1;
			large=k;
		}
	   if(num==1)
		   break;
	}
cout<<large;
return 0;
}

the error i get is:
integer constant is too large for ‘long’ type
i don't want to use array.

>i don't want to use array.
In that case there's probably no other choice left than choosing for a Big Number library like GNU MP, it can handle much bigger numbers than a standard C++ datatype can...

And take a look at Salem's post as well:

  • What is your compiler?
  • What is your OS?

Try to append LL suffix to long long constants.

Comments
Sometimes it's so simple that you even don't think about it :P
ArkM blazes in with both barreLLs for the win ;)

Try

long long num=600851475143LL,large,k,i;

to tell the compiler that the constant is a long long.

frankly, i didn't know that we can marl thread as solved.
But wait, i need to know something more.
While using cin to take a long long int, can simple method,
long long num;
cin>>num;
will do or not ??
and suppose we use it in a code like this,

#include<iostream>
using namespace std;
int main()
{
	long long i;
	for (i=999999999;i<1234567890123;++i)
	if (i%100000000==0)
		cout<<i;
}

it's again showing
integer constant is too large for ‘long’ type

so how to correctly implement it???

> integer constant is too large for ‘long’ type
Oh come on, we've told you how to fix "long long" constants, can't you at least make some intuitive guess as to how to fix "long" ?

And "mark as solved" is a link at one end of the thread (top or bottom, I forget, you can find it).

The integers are too big. You will have to explicitly flush the stream as it takes a hell lot of time to generate the next number which makes your condition true.
Also, postfix LL after the long long constants as already told by others.

#include<iostream>
using namespace std;
int main()
{
	unsigned long long i;
	for (i=999999999LL;i<1234567890123LL;++i)
        if (i%100000000==0)
            cout<<i<<flush; //check here
}

Read this post for a possible explanation: http://www.daniweb.com/forums/post873624.html#post873624

This question has already been answered. Start a new discussion instead.