954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

can long long stor 12 dig num?ifno, without array how 2 do?

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.

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

From this thread I would suggest you to use: <strong>unsigned long long</strong> :)

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

tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
 

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.

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

unsigned long long gives same error.

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
 

Try to append LL suffix to long long constants.

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

Try

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

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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

ubuntu 8.10
compiler g++ 4:4.3.1

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

thanks man, a million thanks. It works

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

>thanks man, a million thanks. It works
So, what is stopping you to mark the thread as Solved.

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

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

Aseem_Pandey
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

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

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You