-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem029.java
More file actions
37 lines (30 loc) · 1.02 KB
/
problem029.java
File metadata and controls
37 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package project_beuler;
import java.util.ArrayList;
public class problem029 {
// Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
//
// If they are then placed in numerical order, with any repeats removed,
// we get the following sequence of 15 distinct terms:
//
// 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
//
// How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
public static void main(String[] args) {
// TODO Auto-generated method stub
int start = 2;
int end = 100;
ArrayList<String> list = new ArrayList<String>();
for(int a = start; a <= end; a++)
for(int b = start; b <= end; b++)
insert(list, ""+Math.pow(a, b));
System.out.println(Interface.Stringify(list));
System.out.println(list.size());
}
public static void insert(ArrayList<String> haystack, String needle) {
for(int i = 0; i < haystack.size(); i++)
if(haystack.get(i).equals(needle))
return;
haystack.add(needle);
return;
}
}