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

Function

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4376    Accepted Submission(s): 858


Problem Description
Let's define the sum of all digits in $x$ as $g(x)$. For example, $g(123) = 1 + 2 + 3 = 6$. Give you a function:
$$
f(x) = Ax^2g(x) + Bx^2 + Cxg^2(x) + Dxg(x)
$$
Find the minimum value of $f(x)$, where $x$ is an integer and $1 \leq x \leq N$.
 

Input
This problem contains multiple test cases.

The first line of the input contains an integer $T (1 \leq T \leq 10^4)$, representing the number of test cases.

Each of the next $T$ lines contains five integers $A, B, C, D, N (0 \leq |A| \leq 10^3, 0 \leq |B|, |C|, |D| \leq 10^6, 1 \leq N \leq 10^6)$ indicating a test case.
 

Output
For each test case output an integer, denoting the answer.
 

Sample Input
2 1 2 3 4 100 4 3 2 1 100
 

Sample Output
10 10
 

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-04-19 20:24:08, Gzip enabled