1452: Buy a house
Description
Xiao Wu graduated from XX Institute of Technology, annual salary n million, he hopes to buy a 60-square-metre house in Zhongguancun mansion, now the price is 2 million, assuming that the house price increases every year, and the small wood annual salary unchanged, and do not eat not to drink, do not pay taxes, every year to accumulate all the N million, Ask for the first year to buy this House (2 million of the home price, income n million)
Input
There are multiple lines, two integers per line N (10<=n<=50), K (1<=k<=20)
Output
For each group of data, if you can buy the house in the 20th year or before, output an integer m, indicating that the earliest need to buy in the first M years, otherwise output impossible, output need to wrap
Sample Input
50 10
40 10
40 8
Sample Output
8
Impossible
10
#include <iostream>
using namespace std;
int main ()
{
int N;
Double K;
while (cin>>n>>k)
{
int i;
Double count2=200,count1=50;
for (i=1;i<20;i++)
{
count1=count1+n;
count2=count2* (1.0+k/100);
if (Count1>=count2)
{
int m=i+1;
cout<<m<<endl;
break;
}
}
if (i==20)
cout<< "Impossible" <<endl;
}
}