Skip to content

Instantly share code, notes, and snippets.

@BillMoriarty
Last active November 1, 2017 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BillMoriarty/6a0dc884569820b40dd89dcb85854b07 to your computer and use it in GitHub Desktop.
Save BillMoriarty/6a0dc884569820b40dd89dcb85854b07 to your computer and use it in GitHub Desktop.
quick algo I wrote for Temple class to determine if a number is a power (if it can be written as q to the k)
public class MyClass {
public static void main(String args[]) {
int N=125;
int q=2;
double k=Math.floor( Math.log(N) );
System.out.println("k is " + k);
for (int j=1; j<=k; j++) {
int result=q;
for(int i=1; i<=N/2; i++){
result= result*q;
if(result == N){
i++;
System.out.println("N is a power with q and k:" + q + ", " + i);
break;
}
}
q++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment