有多行,每行两个整数N(10<=N<=50), K(1<=K<=20)
针对每组数据,如果在第21年或者之前就能买下这套房子,则输出一个整数M,表示最早需要在第M年能买下,否则输出Impossible,输出需要换行
50 10 40 10 40 8
8 Impossible 10
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); int k = scanner.nextInt(); int price = 200; int money = 0; for (int i = 1; i <= 21; i++) { money+=n; if (money>=price){ System.out.println(i); return; } price*= k/100.0+1; } System.out.println("Impossible"); } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ double target = 200.0; int n = sc.nextInt(); int k = sc.nextInt(); int i; for(i=2;i<=21;i++){ target = target*(k+100)/100; if(n*i >= target){ System.out.println(i); break; } } if(i>21){ System.out.println("Impossible"); } } } }