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. MySQL基础 (麦子学员 php 第二阶段)

    通过my.ini配置文件修改字符集:客户端字符集设置:[mysql]default-character-set=utf8 [mysqld] character-set-server=utf8 .设置之 ...

  2. 笔记-python-元类metaclass

    笔记-python-元类metaclass 1.      元类 1.1.    类也是对象 class Person(object): pass 上面的代码会在内存中创建一个类,它也是对象, 可以将 ...

  3. pyhton,数据类型

    标准数据类型 Python3 中有六个标准的数据类型: Number(数字) String(字符串) Tuple(元组) List(列表) Sets(集合) Dictionary(字典) 重点是: 类 ...

  4. saltstack特点

    目录 saltstack特点 saltstack特点 实时交互 所有的minion机器同时执行命令 no freeloader 每一台salt minion上都装有执行master传来的命令所需要的程 ...

  5. Windows usb设备正在使用中

    每次插上u盘之后,弹出的时候,总是提示正在使用中.后来我发现了技巧, 1.打开任务管理器 2.打开底部的 打开资源监视器 按钮 3.然后点击磁盘 4.再次弹出usb 就可以弹出了.

  6. zedboard烧写SD卡启动linux镜像

    1. 先把SD卡格式化,然后把镜像文件拷贝到SD卡,下面应该是没有文件系统的 2. 插上SD卡,Zedboard设置启动模式,有5个跳线帽,配置如下,上电启动 3. 看下串口的输出

  7. samba server on Mac OS X Lion Server

    一般Mac共享通过配置wins,smb即可实现.注意在同一个工作组! 参考:http://computers.tutsplus.com/tutorials/how-to-set-up-an-smb-s ...

  8. centos使用--rpm和yum的关系以及基本用法

    1 RPM包 RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的"添加/删除程序" rpm 执行安装包 二进制包(Binar ...

  9. 使用Unity做项目的时候,一些好的建议

    内容来自这个网站http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/ ,我选取了目前我看得懂的一 ...

  10. 剑指Offer - 九度1349 - 数字在排序数组中出现的次数

    剑指Offer - 九度1349 - 数字在排序数组中出现的次数2013-11-23 00:47 题目描述: 统计一个数字在排序数组中出现的次数. 输入: 每个测试案例包括两行: 第一行有1个整数n, ...