int sums(int x) int s = 0; while(x != 0) { s += x % 10; x = x / 10; } return s;
数位和增量公式: 设 x的数位和为 s_x,x + 1的数位和为 s_x+1
1、当(x+1)⊙10=0 时: s_x + 1 = s_x - 8 ,例如19,数位和为:10
2、 当(x+1)⊙10 != 0 时: s_x + 1 = s_x + 1 ,例如1,2数位和分别为:1,2
//三元表达式写法 (x + 1) % 10 != 0 ? s_x + 1 : s_x - 8;
public long quickMul(long a, long b){ long res = 1; while (b > 0) { if ((b & 1) == 1) { res *= a; } a *= a; b >>= 1; } return res; }
public long quickAdd(long a, long b){ long res = 0; while (b > 0) { if ((b & 1) == 1) { res += a; } a += a; b >>= 1; } return res; }