题目链接:

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. 20165314 2016-2017-2 《Java程序设计》第8周学习总结

    20165314 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 java中的线程 线程的常用方法 GUI线程 多线程的概念 代码托管

  2. python——mysql京东数据库设计案例(源码)

    # 显示界面信息# 循环界面信息# 根据用户输入数据来做相应的选择from pymysql import connect def jingdong_info(): '''#显示界面信息''' prin ...

  3. OpenCV-Python入门教程3-图像基本操作(访问像素点/ROI/通道分离)

    一.获取和修改像素点的值 import cv2img = cv2.imread('lena.jpg') # 100, 90表示行列坐标 px = img[100, 90] print(px) # 获取 ...

  4. 关于前端滚动条,input框等样式的修改

    1.改变滚动条的样式 .orderList::-webkit-scrollbar {/*滚动条整体样式*/ width: 4px; /*高宽分别对应横竖滚动条的尺寸*/ height: 4px;}.o ...

  5. rabbitmq更换数据文件和日志文件的存放位置

    原来的默认位置是/var下 需要将这些文件更换位置 1.先创建数据文件和日志文件存放位置的目录并给权限 mkdir -p /usr/local/rabbitmq/mnesia mkdir -p /us ...

  6. 在PHP中使用AES加密算法加密数据

    算法/模式/填充 16字节加密后数据长度 不满16字节加密后长度 AES/CBC/NoPadding 不支持 AES/CBC/PKCS5Padding AES/CBC/ISO10126Padding ...

  7. [转]启动tensorboard

    https://vivekcek.wordpress.com/tag/tensorboard-windows/   Visualise Computational Graphs with Tensor ...

  8. (二)Makefile——自动编译、清理、安装软件

    每次都要敲击冗长的编译命令,每次都要清理之前的编译中间结果和最终结果,在安装软件时复制剪切大量的动态库,在卸载软件时删除很多的动态库和配置文件.好吧,我被逼向了makefile. helloworld ...

  9. 禁止root直接登陆linux系统

    直接修改文件 # vim /etc/ssh/sshd_config SyslogFacility AUTHPRIV PermitRootLogin no RSAAuthentication yes P ...

  10. DC3求后缀数组板子

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...