https://www.quora.com/How-can-the-pair-a-b-a-b-in-mathbb-Z-be-found-such-that-a-frac-1-3-+-b-frac-1-3-3-is-also-an-integer
第一道是给两个数M和N,求从1到M和1到N之间的数有哪些组合满足两个数立方根的和的三次方是整数
第一题先把式子展开,发现只要找到a^(1/3), b^(1/3), a^(2/3), b^(2/3)(其实也就是a^(1/3), b^(1/3))
感觉这是充分条件。比如3和24,立方根和的立方也是整数
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=180327&page=1#pid2336923
大概的思路就是把式子展开发现只要a^(1 / 3) * b^(2 / 3)和a^(2 / 3) * b^(1 / 3)为整数就能保证结果为整数,如果a^(1 / 3) = b^(1 / 3) * X (X为整数)和b(1 / 3) = a ^ (1 / 3) * X (X为整数),那么a^(1 / 3) * b^(2 / 3) = b * X和a^(2 / 3) * b^(1 / 3) = a * X就肯定是整数,即找到满足a = b * X ^ 3和b = a * X ^ 3的所有a,b组合
public static int cubes(int M, int N){
int count = 1;
for(int a = 1; a <= M; a++){
for(int b = 1; b <= N; b++){
double x = Math.pow(a, 1/3.) + Math.pow(b, 1/3.);
if(x == Math.round(x)) count++;
}
}
return count;
}
How can the pair , , be found such that is also an integer?
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=180327第一道是给两个数M和N,求从1到M和1到N之间的数有哪些组合满足两个数立方根的和的三次方是整数
One can easily observe that this is satisfied whenever a and b are themselves cube of integers. For example if a, b=8, 27; then the expression becomes 125. However this can be generalised to the case where the cube free part of a and b are equal.
Lets define the cube-free part of a given integer N. We first prime factorise the integer. Then we divide N by all cubes (or 6th powers etc.) of primes that occur at least 3 times (or 6 times etc.) in the factorisation. So for the cube free part is 2. Hence the pair 2, 54 would also give an integer in the final expression. It is indeed 128. Now the first case is just a specialisation of this when the cube free part of both integers are 1.
第一题先把式子展开,发现只要找到a^(1/3), b^(1/3), a^(2/3), b^(2/3)(其实也就是a^(1/3), b^(1/3))
感觉这是充分条件。比如3和24,立方根和的立方也是整数
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=180327&page=1#pid2336923
大概的思路就是把式子展开发现只要a^(1 / 3) * b^(2 / 3)和a^(2 / 3) * b^(1 / 3)为整数就能保证结果为整数,如果a^(1 / 3) = b^(1 / 3) * X (X为整数)和b(1 / 3) = a ^ (1 / 3) * X (X为整数),那么a^(1 / 3) * b^(2 / 3) = b * X和a^(2 / 3) * b^(1 / 3) = a * X就肯定是整数,即找到满足a = b * X ^ 3和b = a * X ^ 3的所有a,b组合
- public List<int[]> cubeRoot(int m, int n) {
- List<int[]> res = new ArrayList<int[]>();
- List<Integer> listM = new ArrayList<Integer>();
- List<Integer> listN = new ArrayList<Integer>();
- int cur = 1;
- while(cur <= m / cur / cur) {
- listM.add(cur * cur * cur);. more info on 1point3acres.com
- cur++;. 1point3acres.com/bbs
- }.1point3acres缃�
- cur = 1;
- while(cur <= n / cur / cur) {
- listN.add(cur * cur * cur);
- cur++;. from: 1point3acres.com/bbs
- }
- int a = 1;
- int b = 1;
- HashMap<Integer, HashSet<Integer>> map = new HashMap<Integer, HashSet<Integer>>();
- while(b <= n) {
- for(int numA : listM) {
- a = b * numA;
- if(a <= m) {
- if(!map.containsKey(a)) {
- map.put(a, new HashSet<Integer>());
- }
- map.get(a).add(b);. 1point 3acres 璁哄潧
- res.add(new int[]{a, b});
- }
- else {
- break;
- }
- }.1point3acres缃�
- b++;. From 1point 3acres bbs
- }.鐣欏璁哄潧-涓€浜�-涓夊垎鍦�
- a = 1;
- b = 1;
- while(a <= m) {
- for(int numB : listN) {
- b = a * numB;
- if(b <= n) {
- if(!map.containsKey(a)) {
- map.put(a, new HashSet<Integer>());
- }
- else {
- if(map.get(a).contains(b)) {
- continue;
- }
- }
- map.get(a).add(b);
- res.add(new int[]{a, b});
- }
- else {
- break;
- }
- }
- a++;
- }. 涓€浜�-涓夊垎-鍦帮紝鐙鍙戝竷
- return res;. more info on 1point3acres.com
- }
public static int cubes(int M, int N){
int count = 1;
for(int a = 1; a <= M; a++){
for(int b = 1; b <= N; b++){
double x = Math.pow(a, 1/3.) + Math.pow(b, 1/3.);
if(x == Math.round(x)) count++;
}
}
return count;
}