趣题 CodeForces 111B题解
来源:互联网 发布:linux运维书籍推荐 编辑:程序博客网 时间:2024/05/22 15:23
从这组输入样例来说明题意吧
64 03 15 26 218 410000 3
3112222
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
第 0 行的 6 代表下面有 6 行输入,第 1 行到第 6 行每行有两个数 x 、 y。
题目要求的就是 x 约数的个数,不过这里还有个额外要求,前 y 组数据中出现过的约数就不重复计数了。
如:
x=4 的约数有:1 2 4
x=3 的约数有:1 3 ,由于在这组数据的前面1 组数据中 1这个约数已经出现过了,所以1就不计了,所以第二组输出为1;
题解:用一个数组储存每个约数最迟在第几组输入出现过,d[ divisor ] = idx;
如在第一组数据4 0 出现后,d[1]=d[2]=d[4]=1;
求一个数K的因数用O(K^0.5)的时间解决,所以总的时间复杂度也是可以接受的。
题目链接:here
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
For each query print the answer on a single line: the number of positive integers k such that
64 03 15 26 218 410000 3
3112222
#include<cstdio>#include<cstring>#define N 100100int d[N],n,x,t;int main(){ memset(d,-1,sizeof(d)); scanf("%d",&t); for(int idx=1;idx<=t;idx++) { scanf("%d%d",&x,&n); int ans=0; for(int i=1;i*i<=x;i++) { if((x%i)==0) { int c1=i; int c2=x/i; //一次可以找到两个约数,i和x/i; if(d[c1]+n<idx) ans++; if(c1!=c2 && d[c2]+n<idx) ans++; d[c1]=d[c2]=idx; } } printf("%d\n",ans); } return 0;}
- 趣题 CodeForces 111B题解
- Codeforces B. Taxi 算法题解
- codeforces-158B-Taxi题解
- Codeforces 707B Bakery 题解
- Codeforces 298B Sail 题解
- Codeforces #521B: Cubes 题解
- codeforces T-primes 230 B 素数题解
- Codeforces 347 B Fixed Points 题解
- CodeForces 444B DZY Loves FFT 题解
- 【codeforces 764B】Timofey and cubes 题解
- CodeForces contest/776 A+B+C题解
- Codeforces 803B Distances to Zero 题解
- Codeforces 799B T-shirt buying 题解
- Codeforces 808B Average Sleep Time 题解
- Codeforces 810B Summer sell-off 题解
- Codeforces 520B Two Buttons 题解
- Codeforces 173B Chamber of Secrets 题解
- Codeforces 813B The Golden Age 题解
- BCB key事件中判断Shift、Alt、Ctrl状态
- 一个PHP 性能优化类
- arcgis与c#网站项目安装部署流程
- 结构体对齐——结构体内存布局
- 使用adb shell命令发送按键
- 趣题 CodeForces 111B题解
- NYOJ 205 求余数
- Tomcat中webapps下的项目如何导入到eclipse中
- Struts2常用标签总结
- C/C++:Unions 联合
- 开源CMS赏析
- IOS开发学习笔记(十四)——处理视频
- 域环境相关命令
- Android System进程启动流程