Programming with NTL; help required!

ikj's Avatar, Join Date: May 2009
ikj
Go4Expert Member
im writin this code to generate the powers of 2 n 3 ie (2^i)*(3^j) with i and j from 0 to 64 and since im using NTL i dont have to worry bout system storage constraints.

here's my code:
Code:
 
#include<NTL/ZZ.h>
#include<NTL/vec_ZZ.h>
NTL_CLIENT
#define SIZE_OF_INTEGER 64 
vec_ZZ sort_a(vec_ZZ a, long l)
{
 ZZ temp;
 for(long i=0;i<l;i++)
 {
  for(long j=i;j<l-i-1;j++)
  {
   if(a[i]>a[j])
   {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
   }
  }
 }
 return a;
}
main()
{
      ZZ c,n,d;
      vec_ZZ a,b;
      a.SetLength(power_long(SIZE_OF_INTEGER,2));
       ZZ v;
 v=power_long(2,SIZE_OF_INTEGER);
 long    x=0;
      for(long i=0;i<SIZE_OF_INTEGER;i++)
      {
          for(long j=0;j<SIZE_OF_INTEGER;j++)
          {
              d=(power_long(2,i)*power_long(3,j));
       if(d<v)
  {
   a[x]=d;
   cout<<a[x]<<endl;
   x++;
  }
  else
   break;
           }
       }
 sort_a(a,a.length());
 cout<<endl<<x<<endl;
 for(long k=0;k<a.length();k++)
  cout<<a[k]<<endl;
}
its not workin properly..please help!
thanks for reading!!
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How exactly isn't it working properly? What does it do that you don't expect, or what does it not do that you expected it would?
0
ikj's Avatar, Join Date: May 2009
ikj
Go4Expert Member
i want it to print the powers of 2 and 3 ie (2^i)*(3^j) with i and j from 0 to 64
ie the output shud be
1,2,3,4,6,8,9,12,15,16,18.....
but i dont get that output; wat i get is something else, i get some big negative number (1 followed by 31 zeores in binary form) 64 times and then alot of zeroes instead of what i've mentioned above..
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
3^(SIZE_OF_INTEGER-1) isn't going to fit into a SIZE_OF_INTEGER-bit integer...