F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 127    Accepted Submission(s): 20


Problem Description
Cyy has m kinds of characters,numbered from 1 to m,and the cost of using an i-th character is i.He wants to use these characters to construct N nonempty strings.Every string can not be a prefix of another string.Now he wants to know what the minimum cost is.
 

Input
There are multiple test cases, no more than 1000 cases.
For each case contains two integers n and m on a line.$(1\leq n\leq {10}^{9},2\leq m \leq {10}^{9})$
 

Output
For each test case,output minimum cost in a line.
 

Sample Input
1 2 3 2 5 2 1000 100000
 

Sample Output
1 7 17 10464
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-26 04:02:23, Gzip enabled