Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: computational number theory

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default computational number theory

    Collapse | Copy Code

    public class CubeSum implements Comparable<CubeSum> {
    private final int sum;
    private final int sum2;
    private final int i;
    private final int j;
    private final int a;
    private final int b;

    public CubeSum(int i, int j,int a, int b) {
    this.sum = i*i*i + j*j*j;
    this.i = i;
    this.j = j;
    this.a = a;
    this.b = b;
    this.sum2 = a * a * a + b * b * b;

    }
    public CubeSum(int w

    public int compareTo(CubeSum that) {
    if (this.sum < that.sum) return -1;
    if (this.sum < that.sum) return +1;
    return 0;
    }

    public String toString() {
    return sum + " = " + i + "^3" + " + " + j + "^3";
    }


    public static void main(String[] args) {

    int N = Integer.parseInt(args[0]);

    // initialize priority queue
    MinPQ<CubeSum> pq = new MinPQ<CubeSum>();
    pq.insert(new CubeSum(0,1);

    for (int i = 0,j = 1; i & j <= N; i+=2,j+=2) {
    pq.insert(new CubeSum(i, i,j,j,));
    if(i>0 && j>1)
    {
    pq.insert(new CubeSum(0,i,0,j);
    }
    }
    for(int i =0;i<N;i++)
    {
    for(int j=i+1;j<N;j++)
    {
    if(pq.sum[i] == pq.sum2[j])
    System.out.println("the sum is" + sum[i] + "and the value of i is" + pq.i + " and j is" + pq.j + "and a is" + pq.a + "and b is " + pq.b
    }
    }

    // find smallest sum, print it out, and update
    while (!pq.isEmpty()) {
    CubeSum s = pq.delMin();
    StdOut.println(s);

    }
    }

    }

    am now confused on how to use this program to find all distinct integers a, b, c, and d between 0 and 10^6 such that a3 + b3 = c3 + d3, e.g., 1729 = 9^3 + 10^3 = 1^3 + 12^3.
    this is the code i have devised which i think will work,but everytime i run it,i get an error message when i try to iterate through PQ to determine if sum = sum


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: computational number theory

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    i get an error message
    Please copy the full text of the console with the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: computational number theory

    Quote Originally Posted by bojukwu View Post
    ...how to use this program...
    Step 1a: Make changes so that it will compile.

    Step 1b: Include everything in your post that will enable us to compile and execute a program based on this class.

    Unless and until you do that, there is no Step 2. (But if you complete both parts of Step 1, Steps 2 and 3 will be: Follow Norm's suggestions..)



    Cheers!

    Z
    Last edited by Zaphod_b; July 30th, 2012 at 02:00 PM.

Similar Threads

  1. More number theory
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2012, 01:49 AM
  2. Some help with Java theory?
    By Mudkipers in forum Java Theory & Questions
    Replies: 7
    Last Post: May 12th, 2011, 07:28 AM
  3. How to returned random number to original number?
    By i4ba1 in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 19th, 2011, 04:35 AM
  4. Theory/Question,
    By Time in forum Java Theory & Questions
    Replies: 7
    Last Post: November 9th, 2010, 05:26 PM
  5. Theory Inquiry
    By b_jones10634 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 19th, 2010, 08:21 AM