我的猜測啦
題目應該是要寫成函數
import java.util.Scanner;
public class a_8nz2i {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt ();
int s = sss(n);
System.out.println("s=" + s + " n=" + n);
}
private static int sss(int x) {
int tmp = 0;
while(x>0){
tmp+=x;
x/=2;
}
return tmp;
}
}
不過就我通靈出來的結果
題目應該是要找二進位啦
ㄎㄎ
然後我也好久沒寫 java 了 都在寫 Kotlin
fun main(args: Array<String>) {
val n = readLine()!!.toInt()
val s = sss(n)
println("s=$s n=$n")
}
private fun sss(xx: Int): Int {
var x = xx
var tmp = 0
while (x > 0) {
tmp += x
x /= 2
}
return tmp
}
我積積..陰陰德..了
求老司機載我上車 > < 1000p