zoukankan      html  css  js  c++  java
  • 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 = 1;
        if(H[z]>=x-y)
            flag = 0;
        H[z]=x;
        //cout<<x<<" "<<y<<" "<<z<<" "<<flag<<endl;
        if(flag==0)
            return 0;
        return 1;
    }
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            int x,y;scanf("%d%d",&x,&y);
            int ans = 0;
            for(int j=1;j*j<=x;j++)
            {
                if(x%j==0)
                {
                    if(check(i,y,j))
                        ans++;
                    if(x/j!=j)
                    {
                        if(check(i,y,x/j))
                            ans++;
                    }
                }
            }
            printf("%d
    ",ans);
        }
    }
  • 相关阅读:
    VS2005 Web安装程序 创建程序菜单组
    文件夹 文件 加入/去除 Everyone全控
    [转]asp.net 部署数据库、开始菜单、桌面快捷方式实例
    身边的贵人
    AppCode下的cs类 取得相关路径
    遭遇“windows已经阻止此软件因为无法验证发行者”
    成功不是忽悠
    关于 软件注册授权 防止被大面积免费扩散 的设想
    [转]获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)
    递交辞呈之后
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4981477.html
Copyright © 2011-2022 走看看