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: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 118    Accepted Submission(s): 30


Problem Description
Define function $f(x)= \prod \limits_{i=1}^{len} (x\%10^i)\%(x+1)$, where $len$ represents the digit length of $x$. For example, $f(1023)=(3*23*23*1023)\%1024$.

Define function $g(n,m)= \begin{cases} f(g(n,m-1))& \text{m>1}\\ f(n)& \text{m=1} \end{cases}$. For example, $g(n,2)=f(f(n))$.

You are given $n$ and $m$, please calculate $\sum\limits_{i=1}^m g(n,i)$.
 

Input
The input consists of multiple test cases. The first line contains an integer $T$ $(1 \leq T \leq 20)$ — the number of test cases. The description of the test cases follows.

The only line contains two integers $n,m$ $(1 \leq n,m \leq 10^9)$ .
 

Output
For each test case, print the answer.
 

Sample Input
2 3 4 4102 642
 

Sample Output
12 21262
 

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-23 00:44:12, Gzip enabled