SP8496 NOSQ - No Squares Numbers 题解
To SP8496
这道题可以用到前缀和思想,先预处理出所有的结果,然后 \(O(1)\) 查询即可。
注意:
- 是不能被 \(x^2(x≠1)\) 的数整除的数叫做无平方数。
- \(d\) 可以为 \(0\)。
即对于每次询问,给出 \(s[b][d]-s[a-1][d]\) 的值。
#include<cstdio>
#include<iostream>
using namespace std;
int s[100005][10];//第s[i][j]位存储从0~i中包含j的无平方数的数量
int t;
int a,b,c;
int z,p;
bool find(int x){
for(int i=2;i*i<=x;i++){//注意i=2而非i=1,如原解释注意
if(x%(i*i)==0) return false;
}
return true;
}
int main(){
for(int i=2;i<=100000;i++){
if(find(i)){
z=i;
while(z){
p=z%10;
s[i][p]=1;
z/=10;
}
}
}
for(int i=0;i<=9;i++){
for(int j=2;j<=100000;j++){
s[j][i]+=s[j-1][i];
}
}
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&a,&b,&c);
printf("%d\n",s[b][c]-s[a-1][c]);
}
return 0;
}
SP8496 NOSQ - No Squares Numbers 题解的更多相关文章
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- Hdoj 1905.Pseudoprime numbers 题解
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...
- Hdoj 1058.Humble Numbers 题解
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- [LeetCode] Add Two Numbers题解
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- CF1265B Beautiful Numbers 题解
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...
- CF1157A-Reachable Numbers题解
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Timus : 1002. Phone Numbers 题解
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 ...
随机推荐
- 一文看懂二层接口、三层接口、PVID及VLANIF
关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 文章来源:朱仕耿个人博客 一位同事问了个关于二层和三层端口的概念及区分,以及关于VLANIF. ...
- this-4
ES6函数里的this指的是定义这个函数时外层代码的this,可以理解为:1.ES6箭头函数没有自己的this:2.ES6箭头函数的this是外层代码(定义时,非执行时,也就是词法作用域)this的引 ...
- Blazor和Vue对比学习(基础1.4):事件和子传父
Blazor和Vue的组件事件,都使用事件订阅者模式.相对于上一章的组件属性,需要多绕一个弯,无论Blazor还是Vue,都是入门的第一个难点.要突破这个难点,一是要熟悉事件订阅模式<其实不难& ...
- 论文解读(SimGRACE)《SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation》
论文信息 论文标题:SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation论文作者: ...
- 830. Positions of Large Groups - LeetCode
Question 830. Positions of Large Groups Solution 题目大意: 字符串按连续相同字符分组,超过3个就返回首字符和尾字符 思路 : 举例abcdddeeee ...
- CentOS下sudo的使用和sudoers配置
一.sudo命令 sudo [参数选项] 命令 参数选项 -l:列出目前用户可执行与无法执行的指令: -v:延长密码有效期限5分钟: -u<用户>:以指定的用户作为新的身份.若不加上此参数 ...
- 142_Power BI之同比预测
博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 一.背景 最近刚好在做一个简单同比预测的模型,预测方法很简单,就是累计同比预测,把MTD展示出来. [video widt ...
- cpulimit-限制CPU速率
CPULimit是一个简单的程序,它可以限制指定进程的CPU百分比. 1.安装依赖 root@localhost:~# apt-get -y install git 2.从GitHUB中克隆源码到本地 ...
- leetcode 4. Median of Two Sorted Arrays 寻找两个正序数组的中位数(困难)
一.题目大意 标签: 查找 https://leetcode.cn/problems/median-of-two-sorted-arrays 给定两个大小分别为 m 和 n 的正序(从小到大)数组 n ...
- C/C++ 单元自动化测试解决方案实践
vivo 互联网服务器团队 - Li Qingxin C/C++ 开发效率一直被业内开发人员诟病,单元测试开发效率也是如此,以至于开发人员不愿花时间来写单元测试.那么我们是不是可以通过改善编写单元测试 ...