题目链接:

https://vjudge.net/problem/1377985/origin

题目大意就是要你把一个数字拆开,然后相乘。

要求得数要小于9,否则递归下去。

这里用到一个递归函数:

int f(int x)
{
if(x < ) return x;
int ans = ;
while(x)
{
if(x% != ) ans *= x%;
else ans *= ;
x /= ;
}
return f(ans);
}

这个函数用来求得一个数字最终得到的那个k值是多少。

然后开一个二元数组记录一下,并且用到了前缀和,统计从1开始k值出现的次数:(打表)

void get_table()
{
for(int i = ; i <= MX; ++i) mp[i][f(i)]++;
for(int i = ; i <= MX; ++i)
for(int j = ; j <= ; ++j)
mp[i][j] += mp[i-][j];
}

最后,得到代码如下:(AC代码)

#include <iostream>
#include <cstdio> using namespace std;
const int MX = 1e6+;
int mp[MX][]; int f(int x) //递归求值
{
if(x < ) return x;
int ans = ;
while(x)
{
if(x% != ) ans *= x%;
else ans *= ;
x /= ;
}
return f(ans);
} void get_table() //打表求值
{
for(int i = ; i <= MX; ++i) mp[i][f(i)]++;
for(int i = ; i <= MX; ++i)
for(int j = ; j <= ; ++j)
mp[i][j] += mp[i-][j];
} int main()
{
get_table();
int T;
scanf("%d", &T);
while(T--)
{
int le, ri, k;
scanf("%d%d%d", &le, &ri, &k);
int ans = mp[ri][k] - mp[le-][k]; //left减一的理由是从le开始包括le, 若不减一的话left也会被减掉!
printf("%d\n", ans);
}
return ;
}

如有疑问,欢迎评论!

前缀和的应用 CodeForces - 932B Recursive Queries的更多相关文章

  1. 前缀和:CodeForces 932B Recursive Queries

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

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

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

  3. Codeforces 932.B Recursive Queries

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

  4. CodeForces - 940C + CodeForces - 932B (两道比较好的模拟题)

    940C链接:http://codeforces.com/problemset/problem/940/C C. Phone Numbers time limit per test 2 seconds ...

  5. [Codeforces]817F. MEX Queries 离散化+线段树维护

    [Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...

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

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

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

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

  8. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

  9. 笔记-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 ...

随机推荐

  1. cf1110F 离线+树上操作+线段树区间更新

    自己搞的算法超时了..但是思路没什么问题:用线段树维护每个点到叶子节点的距离即可 /* 线段树维护区间最小值,每次向下访问,就把访问到的点对应的区间段减去边权 到另一颗子树访问时,向上回溯时加上减去的 ...

  2. vue-cli3.0 使用postcss-plugin-px2rem(推荐)和 postcss-pxtorem(postcss-px2rem)自动转换px为rem 的配置方法;

    如何在vue-cli3.0中使用postcss-plugin-px2rem 插件 插件的作用是 自动将vue项目中的px转换为rem . 为什么这三个中要推荐  postcss-plugin-px2r ...

  3. 如何在地址栏(title标签里)和收藏夹里 加上网站的标志ICO、LOGO图片

    第一步:首先你必须要制作一个看起来既清楚又容易辨识的.ico格式的小图片. 我们将图标的大小定义为16x16 像素.此外在制作图形文件的时候,你可能需要把色盘设定成只使用标准的 16 色 Window ...

  4. Spring 整合 Quartz 实现动态定时任务

    复制自:https://www.2cto.com/kf/201605/504659.html 最近项目中需要用到定时任务的功能,虽然Spring 也自带了一个轻量级的定时任务实现,但感觉不够灵活,功能 ...

  5. linux下配置docker和splash(图文)

    所需要环境:ubuntu16.04 第一步用:sudo apt install docker.io 第二步:完成后查看一下有没有成功 命令:docker -v,如果是输入错了写成了大V他会提示你有哪些 ...

  6. Python enumerate() 函数

    描述 enumerate() 函数用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中. Python 2.3. 以上版本可用,2. ...

  7. linux基础练习题(1)

    Linux命令作业(关卡一) 练习题1 理解操作系统的作用,以及各种操作系统的不同 要求: 简述什么是OS 简述应用程序.硬件.OS的关系 列举出3种常见的操作系统 简述Ubuntu和Linux的关系 ...

  8. Python推荐系统库--Surprise实战

    一.使用movieLens数据集 from surprise import KNNBasic, SVD from surprise import Dataset from surprise impor ...

  9. 一个页面中使用多个UEditor

    如何在一个页面中使用多个Ueditor: 引入这些js: <script src="~/Scripts/ueditor/ueditor.config.js"></ ...

  10. 494. Target Sum

    You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symb ...