题目类型:数学
题目难度:中等
*
4;*
2;class Solution {
public int cuttingRope(int n) {
if(n <= 3) return n-1;
int a = n / 3, b = n % 3;
if(b == 0) return (int)Math.pow(3, a);
if(b == 1) return (int)Math.pow(3, a-1) * 4;
return (int)Math.pow(3, a) * 2;
}
}
1
的等差数列前n
项和。class Solution {
public int[][] findContinuousSequence(int target) {
List<int[]> res = new ArrayList<>();
for(int a1 = 1; a1 <= target/2; a1++){
double b = a1 - 0.5;
double n = 0.5 - a1 + Math.pow(b*b+2*target, 0.5);
if(n % 1 == 0){
int[] mar = new int[(int)n];
for(int i = (int)a1; i < (int)n + (int)a1; i++){
mar[i - (int)a1] = i;
}
res.add(mar);
}
}
return res.toArray(new int[res.size()][]);
}
}
class Solution {
public int lastRemaining(int n, int m) {
int fin = 0;
for(int i = 2; i != n+1; i++){
fin = (fin + m) % i;
}
return fin;
}
}