题目链接:

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. 使用 declare 语句和strict_types 声明来启用严格模式:

    使用 declare 语句和strict_types 声明来启用严格模式: Caution: 启用严格模式同时也会影响返回值类型声明. Note: 严格类型适用于在启用严格模式的文件内的函数调用,而不 ...

  2. 使用gulp进行代码压缩

    gulp是一个很不错的前端自动化工具,可以帮我们完成一些重复性操作,比如html.css和js代码的压缩.合并.混淆等,虽然这些操作可以通过一些在线工具帮我们实现,但不断重复地复制粘贴肯定比不上一句命 ...

  3. You are my brother

    问题 : You are my brother 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Little A gets to know a new friend, Little B, ...

  4. 将眼底图片生成的txt文件进行格式化处理

    # -*- coding: utf-8 -*- """ 将图片转换生成的txt文件进行格式化处理 """ import os import ...

  5. centos7.4/rehat7.0系统安装

    以下是安装过程:(图解),以下是rehat为例 这里可以改为centos的镜像 之后就可以用了,记得做快照!!! 拓展:分离使用 效果:

  6. 步步为营-74-Request,Response和server的其他成员

    Request 1 Request.UrlReferrer 获取请求的来源 2 Request.UserHostAddress 获取访问者的IP地址 3 Request.Cookies 获取浏览器发送 ...

  7. 一脸懵逼学习Nginx及其安装,Tomcat的安装

    1:Nginx的相关概念知识: 1.1:反向代理: 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到 ...

  8. JDK 自带压缩解压流

    代码如下 package com.test.java.zip; import java.io.BufferedInputStream; import java.io.BufferedOutputStr ...

  9. Dubbo 服务集群容错配置

    Dubbo集群容错是靠配置cluster属性来做 支持改属性的标签为<dubbo:service>,<dubbo:referece>,<dubbo:consumer> ...

  10. [转]解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.

    来源:http://www.cnblogs.com/sprinng/p/5141233.html 1.添加M2_HOME的环境变量 2.Preference->Java->Installe ...