M - Function and Function (思维题)

If we define , do you know what function  means?

Actually,  calculates the total number of enclosed areas produced by each digit in . The following table shows the number of enclosed areas produced by each digit:

Enclosed AreaDigitEnclosed AreaDigit
0150
1061
2070
3082
4191

For example, , and .

We now define a recursive function  by the following equations:

For example, , and .

Given two integers  and , please calculate the value of .

Input

There are multiple test cases. The first line of the input contains an integer (about ), indicating the number of test cases. For each test case:

The first and only line contains two integers  and  (). Positive integers are given without leading zeros, and zero is given with exactly one '0'.

Output

For each test case output one line containing one integer, indicating the value of .

Sample Input

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

Sample Output

5
18
2
0
0
1000000000

Hint

题目没有粘全。。。。。

关键是有技巧。。

就是所有的数在经过题目中的条件下,一定的循环后一定会变成0,这个时候单独处理就不会超时。。。

#include <iostream>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
    int T;
    int x,k;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&x,&k);
        if(k==0)
            printf("%d\n",x);
        else
        {
            int ans;
            while(k--)
            {
                ans = 0;
                if(x==0)
                {
                    if(k%2==0)
                        ans = 1;
                    else
                        ans = 0;
                    break;
                }
                while(x)
                {
                    int j = x%10;
                    if(j==0||j==4||j==6||j==9)
                        ans+=1;
                    else if(j==8)
                        ans+=2;
                    else ans+=0;
                    x/=10;
                }
                x = ans;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值