304952: CF940B. Our Tanya is Crying Out Loud
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Our Tanya is Crying Out Loud
题意翻译
给你1个数n和k,每次有两种操作,第一种1是减去1花费为a,第二种是除以k(当k能整除n时才可以进行)花费为b,求最少使n变为1的花费。 输入格式: 输入四行,分别为n,k,A,B ( 1<=n,k,a,b<=2*10^9 ). Translated by @logeadd题目描述
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers $ n $ , $ k $ , $ A $ and $ B $ . There is a number $ x $ , which is initially equal to $ n $ . You are allowed to perform two types of operations: 1. Subtract 1 from $ x $ . This operation costs you $ A $ coins. 2. Divide $ x $ by $ k $ . Can be performed only if $ x $ is divisible by $ k $ . This operation costs you $ B $ coins. What is the minimum amount of coins you have to pay to make $ x $ equal to $ 1 $ ?输入输出格式
输入格式
The first line contains a single integer $ n $ ( $ 1<=n<=2·10^{9} $ ). The second line contains a single integer $ k $ ( $ 1<=k<=2·10^{9} $ ). The third line contains a single integer $ A $ ( $ 1<=A<=2·10^{9} $ ). The fourth line contains a single integer $ B $ ( $ 1<=B<=2·10^{9} $ ).
输出格式
Output a single integer — the minimum amount of coins you have to pay to make $ x $ equal to $ 1 $ .
输入输出样例
输入样例 #1
9
2
3
1
输出样例 #1
6
输入样例 #2
5
5
2
20
输出样例 #2
8
输入样例 #3
19
3
4
2
输出样例 #3
12