codeforces 111B/112D Petya and Divisors
题目:Petya and Divisors
传送门:
http://codeforces.com/problemset/problem/111/B
http://codeforces.com/problemset/problem/112/D
分析:
很容易想到读入x[i]、y[i],寻找x[i]的因数,判断一下是不是x[i-y[i]]、x[i-y[i]+1]...x[i-1]的某个数因数;但这样会超时;考虑以下两个优化:(1)寻找x[i]因数时循环范围只需要从j∈[0,sqrt(x[i])],但循环体内同时判断两个因数j、x[i]/j(注意当j*j==x[i]的情况);(2)把子问题“判断一下因数j是不是x[i-y[i]]、x[i-y[i]+1]...x[i-1]的某个因数”转变为问题“因数j最后一次位置出现在不在[i-y[i],i-1]”求解,并更新因数j最后一次位置。
代码:
#include<cstdio>
int n,last[];
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
for(int i=,x,y,ans;i<=n;++i){
scanf("%d%d",&x,&y);
ans=;
for(int j=;j*j<=x;++j)
if(x%j==){
if(last[j]<i-y)++ans;last[j]=i;
if(j*j==x)continue;
if(last[x/j]<i-y)++ans;last[x/j]=i;
}
printf("%d\n",ans);
}
return ;
}
codeforces 111B/112D Petya and Divisors的更多相关文章
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- B. Petya and Divisors 解析(思維)
Codeforce 111 B. Petya and Divisors 解析(思維) 今天我們來看看CF111B 題目連結 題目 略,請看原題 前言 看了別人的解答就豁然開朗 @copyright p ...
- CodeForces 111B - Petya and Divisors 统计..想法题
找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- codeforces 111C/112E Petya and Spiders
题目: Petya and Spiders传送门: http://codeforces.com/problemset/problem/111/C http://codeforces.com/probl ...
- codeforces 111A/112C Petya and Inequiations
题目:Petya and Inequiations传送门: http://codeforces.com/problemset/problem/111/A http://codeforces.com/p ...
- 【Codeforces 111C】Petya and Spiders
Codeforces 111 C 题意:给\(n\times m\)的网格,每个点上有一个蜘蛛,每个蜘蛛可以向上.下.左.右走一步或者不动,问最多能存在多少没有蜘蛛的点. 思路1: 首先因为\(n\) ...
- Codeforces 1082 G - Petya and Graph
G - Petya and Graph 思路: 最大权闭合子图 对于每条边,如果它选了,那么它连的的两个点也要选 边权为正,点权为负,那么就是求最大权闭合子图 代码: #pragma GCC opti ...
- CF刷题-Codeforces Round #481-G. Petya's Exams
题目链接:https://codeforces.com/contest/978/problem/G 题目大意:n天m门考试,每门考试给定三个条件,分别为:1.可以开始复习的日期.2.考试日期.3.必须 ...
随机推荐
- js 数组相减 (一个数组去掉不符合条件的子数组)
数组相减?我也希望将来在ES8或者更好js版本能带来数组之间相互运算的方法,但是现在不能,咱们只能靠已有的方法实现: var arr1 = [2,3,5,88,99,444,66],arr2 = [2 ...
- kali 开启xdebug
1.安装xdebug 参考https://xdebug.org/docs/install 2.配置 # vi /etc/php/7.3/mods-available/xdebug.inizend_ex ...
- Unable to load dynamic library 'zip.so' on Centos 6.8 useing php7.3
背景: Centos6.8服务器升级php版本,从7.1升级到7.3,常用扩展都安装完成之后,报:Class 'ZipArchive' not found.一看就是zip扩展没有,需要手动安装了. 中 ...
- Mysql 在 select 查询时追加(添加)一个字段并指定值
在特定时候,在 mysql 的查询结果中我们需要追加一个字段来实现某些特定的功能,这时我们可以用到以下语法来实现 值 as 字段比如我们需要给这个查询结果追加一个 xx 字段并赋值为 null ,可以 ...
- android概念-android学习第二天
一:1G到4G(generation) 1G 大哥大 -- 电话 2G 小灵通 gsm标准 发短信 wap.baidu.com -- 电话和短信 3G 沃 www.baidu.com 7.2M/s - ...
- Edit the AlarmClock in AOSP with android-studio
1. git the AlarmClock source code on AOSP 2. select 'import project' by android-studio & we will ...
- 获取Linux内核未导出符号的几种方式
从Linux内核的2.6某个版本开始,内核引入了导出符号的机制.只有在内核中使用EXPORT_SYMBOL或EXPORT_SYMBOL_GPL导出的符号才能在内核模块中直接使用.然而,内核并没有导出所 ...
- 左侧菜单收缩的实现(包括,筛选器,addclass、removeclass、绑定事件,链式编程)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js字符串相关方法
<script> // 使用索引位置来访问字符串中的每个字符: var carname = 'Volvo XC60'; var character = carname[7]; consol ...
- elasticsearch 基础 —— Get API
Get API get API允许根据其id从索引中获取指定类型的JSON文档.以下示例从名为twitter的索引获取JSON文档,该索引类型名为_doc,id值为0: GET twitter/_do ...