假设 n为贷款的原值,m为每月支付的分期付款金额,k为分期付款还清贷款所需的总月数,且利率按月累计。
利率为p,则
就好比如,你第一个月的利率为(1+p),第二个月的利率就为(1+p)^2,依次类推。
(银行利率不太懂,简单记录一下)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
double l=0;
double r=10;
double mid=0;
while(r-l>=0.0001){
mid = (l+r)/2;
if(judge(mid,k,n,m)){
l = mid;
}
else
r=mid;
}
System.out.println(String.format("%.1f",mid*100));
}
public static boolean judge(double mid,int k,int n,int m){
double sum=0;
for(int i=1;i<=k;i++){
sum+=(double)1/Math.pow(1+mid,i);
}
return sum>=(double)n/m;
}
}
class Node{
int x,y;
}
class cmp implements Comparator<Node> {
@Override
public int compare(Node o1, Node o2) {
return o1.y - o2.y;
}
}
//快读
class Read{
StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public int nextInt() throws Exception{
st.nextToken();
return (int)st.nval;
}
}