B. Recursive Queries
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Let us define two functions f and g on positive integer numbers.

You need to process Q queries. In each query, you will be given three integers lr and k. You need to print the number of integers xbetween l and r inclusive, such that g(x) = k.

Input

The first line of the input contains an integer Q (1 ≤ Q ≤ 2 × 105) representing the number of queries.

Q lines follow, each of which contains 3 integers lr and k (1 ≤ l ≤ r ≤ 106, 1 ≤ k ≤ 9).

Output

For each query, print a single line containing the answer for that query.

Examples
input
4
22 73 9
45 64 6
47 55 7
2 62 4
output
1
4
0
8
input
4
82 94 6
56 67 4
28 59 9
39 74 4
output
3
1
1
5
Note

In the first example:

  • g(33) = 9 as g(33) = g(3 × 3) = g(9) = 9
  • g(47) = g(48) = g(60) = g(61) = 6
  • There are no such integers between 47 and 55.
  • g(4) = g(14) = g(22) = g(27) = g(39) = g(40) = g(41) = g(58) = 4

题目大意:f(x)的值是x非零数位的乘积.q组询问,每次问[l,r]之间的x,有多少g(x) = k;

分析:多组询问想到预处理,每次问个数想到前缀和,那么预处理一个前缀和就好了.

#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; int q,a[],sum[][]; int solve(int x)
{
if (x < )
return x;
if (a[x])
return a[x];
int res = ;
while (x)
{
int temp = x % ;
if (temp != )
res *= temp;
x /= ;
}
return a[x] = solve(res);
} int main()
{
scanf("%d",&q);
for (int i = ; i <= ; i++)
{
if (i < )
a[i] = i;
else
a[i] = solve(i);
}
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
sum[i][j] += sum[i - ][j];
sum[i][a[i]]++;
}
while (q--)
{
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
printf("%d\n",sum[r][k] - sum[l - ][k]);
} return ;
}

Codeforces 932.B Recursive Queries的更多相关文章

  1. Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    B. Recursive Queries   time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. sql server: Graphs, Trees, Hierarchies and Recursive Queries

    --------------------------------------------------------------------- -- Chapter 09 - Graphs, Trees, ...

  3. sql script: Graphs, Trees, Hierarchies and Recursive Queries

    --------------------------------------------------------------------- -- Inside Microsoft SQL Server ...

  4. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  5. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

  6. codeforces 1217E E. Sum Queries? (线段树

    codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...

  7. 笔记-Recursive Queries

    Recursive Queries \[m_{l,r}=\textrm{id}(\max_{i=l}^r a_i)\\ f(l,r)= \begin{cases} (r-l+1)+f(l,m_{l,r ...

  8. Codeforces 1117G Recursive Queries [线段树]

    Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\ma ...

  9. 前缀和:CodeForces 932B Recursive Queries

    Description Let us define two functions f and g on positive integer numbers. You need to process Q q ...

随机推荐

  1. hasOwnProperty自我理解

    暂时不考虑ES6中symbol,hasOwnProperty()方法返回的是一个对象上是否包含一个指定属性,如果含有则返回true,如果没有则返回false.   和 in 运算符不同,该方法会忽略掉 ...

  2. P1414 又是毕业季II (数学?

    题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在毕业晚会上,相信,这一定 ...

  3. Matplotlib 图表的基本参数设置

    1.图名,图例,轴标签,轴边界,轴刻度,轴刻度标签 # 图名,图例,轴标签,轴边界,轴刻度,轴刻度标签等 df = pd.DataFrame(np.random.rand(10,2),columns= ...

  4. HyperLedger Fabric 1.4 区块链技术形成(1.2)

    在比特币诞生之时,没有区块链技术概念,当人们看到比特币在无中心干预的前提下,还能安全.可靠的运行,比特币网络打开了人们的想象空间:技术专家们开始研究比特币的底层技术,并抽象提取出来,形成区块链技术,或 ...

  5. 17-比赛2 F - Fox And Two Dots (dfs)

    Fox And Two Dots CodeForces - 510B ================================================================= ...

  6. Altium Designer之模块复用——设备图表符与Snippets

    Altium Designer中的设备图表符(Device Sheet Symbol)和Snippets是设计中模块复用的利器,下面简单介绍下这个两个功能的使用. 一.设备图表符(Device She ...

  7. 使用CSS3制作各种形状

    CSS3的一个非常酷的特性是允许我们创建各种规则和不规则形状的图形,从而可以减少图片的使用.以前只能在Photoshop等图像编辑软件中制作的复杂图形现在使用CSS3就可以完成了.通过使用新的CSS属 ...

  8. 论如何入门地使用vscode

    微软大法好啊 这货更像是个gedit 以下内容只适合Oiers使用 本文档只适合新手引导的阶段使用 下载 这个是链接 可见这东西是和Emacs一样跨系统的 不知道为什么下载速度贼快 配置 还记得我们用 ...

  9. Activiti入门 -- 轻松解读数据库

    相关文章: <史上最权威的Activiti框架学习指南> <Activiti入门 --环境搭建和核心API简介> 在Activiti中,相对前身JBPM基础上又额外多了5张,框 ...

  10. .net面试那些事

    2014-3-30这天从昆明来到了江苏无锡,一周时间,不同地方不同感触. 在经过长达35小时的火车,在上海南见到了我弟,在经过两小时汽车到了无锡.回想起来....在坐汽车途中,虽然自己已很累,但从上海 ...