题目链接:

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. AppServ安装到一半卡住的问题

    今天在笔记本安装AppServ的时候,运行到Installing mysql service时就卡住不动了,因为之前在自己的台式电脑安装过AppServ,当时是一步成功的,所以觉得这个问题莫名其妙,因 ...

  2. linux下搭建SVN

      官网下载: http://subversion.apache.org/packages.html SVN客户端:TortoiseSVN :https://tortoisesvn.net/downl ...

  3. 优先选择nullptr而不是0和NULL

    我们知道:0是一个int,而不是一个指针.如果C++在一个只有指针才能够使用的上下文中发现它只有一个0,那么它会勉强将0解释成空指针,但那时一种倒退行为.C++的主要方针是0就是一个int,而不是指针 ...

  4. RabbitMQ中客户端的Channel类里各方法释义

    // The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "Lic ...

  5. C#动态系统托盘图标

    C#动态系统托盘图标 利用timer组件定时执行变化. using System; using System.Windows.Forms; namespace DynamicStockIcon { p ...

  6. 使用python解决算法和数据结构--使用栈实现符号匹配

    现在要自己来实现这些数据结构和常用算法了. 把基础再打牢一些. 栈的作用很大,无须多言. 我尽量看了题目要求,自己来实现代码的. # coding = utf-8 class Stack: def _ ...

  7. java 使用jdbc连接Greenplum数据库和Postgresql数据库

    1.公司使用的Greenplum和Postgresql,确实让我学到不少东西.简单将使用jdbc连接Greenplum和Postgresql数据库.由于使用maven仓库,不能下载Greenplum的 ...

  8. Caused by: java.net.ConnectException: Connection refused: master/192.168.3.129:7077

    1:启动Spark Shell,spark-shell是Spark自带的交互式Shell程序,方便用户进行交互式编程,用户可以在该命令行下用scala编写spark程序. 启动Spark Shell, ...

  9. 【Android】setHapticFeedbackEnabled 设置

    使其在触摸的时候没有触感反馈.接着设置长按事件的监听. 代码在:launcher launcher->setupViews方法 // Setup the workspacemWorkspace. ...

  10. 经典的XSS案例

    在做安全审计的时候,通过常用的<script>alert(1)</script>无法发现该XSS