Last active
November 1, 2017 00:09
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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