import java.lang.*;
import java.util.*;
import java.io.*;

import javax.swing.event.*; 
import javax.swing.*;   
import javax.swing.table.*;
      
import java.awt.*;
import java.awt.event.*;                       
import java.awt.datatransfer.*;

import javax.imageio.*;
import java.awt.image.*;
import java.util.zip.*;

public class prime_listc {
  float prime_factor[];
  int num_primes;
  int num_alloc_primes;
  prime_listc(int n) {
    num_primes = n;
    if (n == 0) {
      num_alloc_primes = 1;
      prime_factor = new float[1];
    } else {
      num_alloc_primes = n;
      prime_factor = new float[n];
    }
    //int nl = main_app.primes_table75.length;
    for (int i = 0;i < n;i++) {
      //prime_factor[i] = (float) get_prime_integer_factor(i);
      prime_factor[i] = main_app.primes_table75[i];
      //System.out.println(prime_factor[i]);
    }
  }
  void add_prime() {
    if (num_primes >= num_alloc_primes) {
      num_alloc_primes = num_alloc_primes * 2;
      float new_array[] = new float[num_alloc_primes];
      for (int i = 0;i < num_primes;i++) {
        new_array[i] = prime_factor[i];
      }
      prime_factor = new_array;
    }
    //float p = (float) get_prime_integer_factor(num_primes);
    float p = main_app.primes_table75[num_primes];
    prime_factor[num_primes] = p;
    num_primes = num_primes + 1;
  }
  void gen_harmonics(Vector harmonic_list,float freq,int index,float limit) {
    harmonic_list.add(new Float(freq));
    while (index >= 0) {
      float f = freq * prime_factor[index];
      if (f <= limit) {
        gen_harmonics(harmonic_list,f,index,limit);
      }
      index = index - 1;
    }
  }
  float get_harmonic_freq(int h) {
    float freq = 1.0f;
    if (h == 0) {return 0.0f;}
    for (int i = 0;i < 4;i++) {
      int f = get_prime_integer_factor(i);
      while ((h % f) == 0) {
        h = h / f;
        freq = freq * prime_factor[i];
      }
    }
    if (h == 1) {return freq;}
    int i = get_prime_index(h);
    if (i >= num_primes) {return 0.0f;}
    return freq * prime_factor[i];
  }
  static int get_prime_integer_factor(int i) {    
    if (i == 0) {return 2;}
    if (i == 1) {return 3;}
    int i2 = (i / 2);
    int i3 = (i % 2);    
    return ((i2*6)+(i3*2)-1);
  }
  static int get_prime_index(int p) {
    int a = ((p + 3) / 6);
    if (p == 2) {return 0;}
    if (p == 3) {return 1;}
    if ((p % 6) == 1) {return (a*2)+1;}
    else {return (a*2);}
  }

}

