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/problem/B
Description
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.
Input
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.
Output
For each query print the answer on a single line: the number of positive integers k such that 
Sample Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Sample Output
3
1
1
2
2
22
HINT
题意
给你n次询问,每次给你一个x,y
然后让你输出,x这个数中的因子有多少个并没有在这个数的前y个数中出现过
题解:
对于每次询问,我们直接暴力统计因子个数
对于每一个因子,我们都记录一下这个因子最后出现在在什么时候,然后我们再判断是否ans++就好了
代码
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std; map<int,int> H;
int check(int x,int y,int z)
{ int flag = ;
if(H[z]>=x-y)
flag = ;
H[z]=x;
//cout<<x<<" "<<y<<" "<<z<<" "<<flag<<endl;
if(flag==)
return ;
return ;
}
int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x,y;scanf("%d%d",&x,&y);
int ans = ;
for(int j=;j*j<=x;j++)
{
if(x%j==)
{
if(check(i,y,j))
ans++;
if(x/j!=j)
{
if(check(i,y,x/j))
ans++;
}
}
}
printf("%d\n",ans);
}
}
Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力的更多相关文章
- Codeforces Beta Round #85 (Div. 1 Only) A. Petya and Inequiations 贪心
A. Petya and Inequiations Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)
题目链接:http://www.codeforces.com/problemset/problem/112/A题意:忽略大小写,比较两个字符串字典序大小.C++代码: #include <cst ...
- Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)
C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...
- Codeforces Beta Round #91 (Div. 2 Only) A. Lucky Division【暴力/判断是不是幸运数字4,7的倍数】
A. Lucky Division time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- Meta标签详解(转)
引言 您的个人网站即使做得再精彩,在“浩瀚如海”的网络空间中,也如一叶扁舟不易为人发现,如何推广个人网站,人们首先想到的方法无外乎以下几种: ● 在搜索引擎中登录自己的个人网站 ● 在知名网站加入你个 ...
- 只用css实现“每列四行,加载完一列后数据自动填充到下一列”的效果
只用css实现“每列四行,加载完一列后数据自动填充到下一列”的效果.这个题目用图表示如下: 如果将题目换成“只用css实现每行四列,加载完一行后数据自动填充到下一行”,那这个问题就简单多了,相信大家都 ...
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
使用HttpURLConnection下载文件时经常会出现 java.io.FileNotFoundException文件找不到异常,下面介绍下解决办法 首先设置tomcat对get数据的编码:con ...
- setImageResource和setImageDrawable区别
ImageView设置图片的方式有很多钟,可以在xml里面写android:src=”@drawable/xxx”,也可以在java代码里面设置. 在java里面的设置方式也有多种,方法包括:setI ...
- 【剑指offer 面试题17】合并两个排序的链表
思路: 比较两个链表端点值的大小,通过递归的方式排列. #include <iostream> using namespace std; struct ListNode { int val ...
- 《Python 学习手册4th》 第九章 元组、文件及其他
''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书) “重点 ...
- 根据关键词获取进程ID然后杀掉进程
例如需要杀掉监听进程,如下: [oracle@kel ~]$ ps -ef|grep lsnr oracle 4973 1 1 19:40 ? 00:00:00 /home/oracle/produc ...
- 某酒店2000W数据
某酒店2000W数据 2000万开房信息 [某酒店2000w数据 ct2000(解压密码:sjisauisa是就数据8很舒适好sjjss).rar] 国内安全漏洞监测平台乌云(WooYun.org)近 ...
- Tkinter教程之Canvas篇(2)
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811888 '''Tkinter教程之Canvas篇(2)''''''9.创建item的tag ...
- Android自定义TTF字体
前言: 在Android Design中一个设计手册.在设计手册中有常用的UI图标,图标大小规范等. 其中,有一个TTF字体,以前感觉没什么用.但是我在学习时,常看到有许多开发者使用Google 提供 ...