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

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 10
Reputation: Aseem_Pandey is an unknown quantity at this point 
Solved Threads: 0
Aseem_Pandey Aseem_Pandey is offline Offline
Newbie Poster

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

 
0
  #1
Jun 8th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
0
  #2
Jun 8th, 2009
a) post what you actually tried, not a description.
b) post your actual error messages
c) tell us what your OS/Compiler is.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

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

 
0
  #3
Jun 8th, 2009
From this thread I would suggest you to use: unsigned long long

>can long long store 12 digit numbers.
Depends on what your compiler is...
Last edited by tux4life; Jun 8th, 2009 at 4:31 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Aseem_Pandey is an unknown quantity at this point 
Solved Threads: 0
Aseem_Pandey Aseem_Pandey is offline Offline
Newbie Poster

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

 
0
  #4
Jun 8th, 2009
this is my code. Problem as described above.
We have to find largest prime factor of a number.
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.  
  6. long long num=600851475143,large,k,i;
  7.  
  8. for(i=2;;++i)
  9. { k=i;
  10. if(num%i==0)
  11. { num/=i;
  12. i=k-1;
  13. large=k;
  14. }
  15. if(num==1)
  16. break;
  17. }
  18. cout<<large;
  19. return 0;
  20. }
the error i get is:
integer constant is too large for ‘long’ type
i don't want to use array.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Aseem_Pandey is an unknown quantity at this point 
Solved Threads: 0
Aseem_Pandey Aseem_Pandey is offline Offline
Newbie Poster

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

 
0
  #5
Jun 8th, 2009
unsigned long long gives same error.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

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

 
0
  #6
Jun 8th, 2009
>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?
Last edited by tux4life; Jun 8th, 2009 at 4:36 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

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

 
2
  #7
Jun 8th, 2009
Try to append LL suffix to long long constants.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
0
  #8
Jun 8th, 2009
Try
long long num=600851475143LL,large,k,i;
to tell the compiler that the constant is a long long.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Aseem_Pandey is an unknown quantity at this point 
Solved Threads: 0
Aseem_Pandey Aseem_Pandey is offline Offline
Newbie Poster

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

 
0
  #9
Jun 8th, 2009
ubuntu 8.10
compiler g++ 4:4.3.1
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Aseem_Pandey is an unknown quantity at this point 
Solved Threads: 0
Aseem_Pandey Aseem_Pandey is offline Offline
Newbie Poster

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

 
0
  #10
Jun 8th, 2009
thanks man, a million thanks. It works
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC