题目思路代码
题目http://vj.saikr.com/contest/17/problem/C
21 天内刷1道题,22 天内刷2道题,23 天内刷3道题,如图所示
当输入为9时,即第9天,一共需要刷:21 * 1 + 22 * 2 + (9-23 )*3 = 19道题
先求出9所在的区间,2的次方power为多少,再相加就好了
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner out = new Scanner(System.in);
// System.out.println("输入一个int型数据:");
int num = out.nextInt();
int sum = 2, power = 1;
while(num>sum){
power += 1;
sum += Math.pow(2, power);
}
sum -= Math.pow(2, power);
int x=1,res=0;
while(x


