Programming with NTL; help required!

Discussion in 'C' started by ikj, May 25, 2009.

  1. ikj

    ikj New Member

    Joined:
    May 14, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    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!!
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     
  3. ikj

    ikj New Member

    Joined:
    May 14, 2009
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    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..
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    3^(SIZE_OF_INTEGER-1) isn't going to fit into a SIZE_OF_INTEGER-bit integer...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice