Digit Product

[SNCPC2019] Digit Product

题面翻译

【题目描述】

定义正整数 x x x 的 “数字乘积” f ( x ) f(x) f(x) 为其所有数字的乘积。例如, f ( 1234 ) = 1 × 2 × 3 × 4 = 24 f(1234) = 1 \times 2 \times 3 \times 4 = 24 f(1234)=1×2×3×4=24 f ( 100 ) = 1 × 0 × 0 = 0 f(100) = 1 \times 0 \times 0 = 0 f(100)=1×0×0=0

给定两个整数 l l l r r r,请计算以下值:
( ∏ i = l r f ( i ) ) m o d    ( 1 0 9 + 7 ) (\prod_{i=l}^r f(i)) \mod (10^9+7) (i=lrf(i))mod(109+7)
如果你不知道 ∏ \prod 表示什么,上述表达式等同于
( f ( l ) × f ( l + 1 ) × ⋯ × f ( r ) ) m o d    ( 1 0 9 + 7 ) (f(l) \times f(l+1) \times \dots \times f(r)) \mod (10^9+7) (f(l)×f(l+1)××f(r))mod(109+7)

【输入格式】

有多个测试用例。输入的第一行包含一个整数 T T T(大约 1 0 5 10^5 105),表示测试用例的数量。对于每个测试用例:

第一行且唯一一行包含两个整数 l l l r r r 1 ≤ l ≤ r ≤ 1 0 9 1 \le l \le r \le 10^9 1lr109),表示给定的两个整数。这些整数没有前导零。

【输出格式】

对于每个测试用例,输出一行,包含一个整数,表示答案。

【样例解释】

对于第一个样例测试用例,答案是 9 ! m o d    ( 1 0 9 + 7 ) = 362880 9! \mod (10^9+7) = 362880 9!mod(109+7)=362880

对于第二个样例测试用例,答案是 ( f ( 97 ) × f ( 98 ) × f ( 99 ) ) m o d    ( 1 0 9 + 7 ) = ( 9 × 7 × 9 × 8 × 9 × 9 ) m o d    ( 1 0 9 + 7 ) = 367416 (f(97) \times f(98) \times f(99)) \mod (10^9+7) = (9 \times 7 \times 9 \times 8 \times 9 \times 9) \mod (10^9+7) = 367416 (f(97)×f(98)×f(99))mod(109+7)=(9×7×9×8×9×9)mod(109+7)=367416

翻译来自于:ChatGPT

题目描述

Define the ‘‘digit product’’ f ( x ) f(x) f(x) of a positive integer x x x as the product of all its digits. For example, f ( 1234 ) = 1 × 2 × 3 × 4 = 24 f(1234) = 1 \times 2 \times 3 \times 4 = 24 f(1234)=1×2×3×4=24, and f ( 100 ) = 1 × 0 × 0 = 0 f(100) = 1 \times 0 \times 0 = 0 f(100)=1×0×0=0.

Given two integers l l l and r r r, please calculate the following value:
( ∏ i = l r f ( i ) ) m o d    ( 1 0 9 + 7 ) (\prod_{i=l}^r f(i)) \mod (10^9+7) (i=lrf(i))mod(109+7)
In case that you don’t know what ∏ \prod represents, the above expression is the same as
( f ( l ) × f ( l + 1 ) × ⋯ × f ( r ) ) m o d    ( 1 0 9 + 7 ) (f(l) \times f(l+1) \times \dots \times f(r)) \mod (10^9+7) (f(l)×f(l+1)××f(r))mod(109+7)

输入格式

There are multiple test cases. The first line of the input contains an integer T T T (about 1 0 5 10^5 105), indicating the number of test cases. For each test case:

The first and only line contains two integers l l l and r r r ( 1 ≤ l ≤ r ≤ 1 0 9 1 \le l \le r \le 10^9 1lr109), indicating the given two integers. The integers are given without leading zeros.

输出格式

For each test case output one line containing one integer indicating the answer.

样例 #1

样例输入 #1

2
1 9
97 99

样例输出 #1

362880
367416

提示说明

For the first sample test case, the answer is 9 ! m o d    ( 1 0 9 + 7 ) = 362880 9! \mod (10^9+7) = 362880 9!mod(109+7)=362880.

For the second sample test case, the answer is ( f ( 97 ) × f ( 98 ) × f ( 99 ) ) m o d    ( 1 0 9 + 7 ) = ( 9 × 7 × 9 × 8 × 9 × 9 ) m o d    ( 1 0 9 + 7 ) = 367416 (f(97) \times f(98) \times f(99)) \mod (10^9+7) = (9 \times 7 \times 9 \times 8 \times 9 \times 9) \mod (10^9+7) = 367416 (f(97)×f(98)×f(99))mod(109+7)=(9×7×9×8×9×9)mod(109+7)=367416.

代码内容

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll p=1e9+7;

int main()
{
    ll T;
    cin>>T;
    
    while(T--)
    {
        ll l,r;
        cin>>l>>r;
        
        ll ans=1;
        for(ll i=l;i<=r;i++)
        {
            ll temp=i;
            while(temp)
            {
                ans=ans*(temp%10)%p;
                temp/=10;
            }
            if(ans==0) break;
        }
        cout<<ans<<endl;
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值