zoukankan      html  css  js  c++  java
  • codeforces 111B Petya and Divisors

    题目:

    Description

    Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:

    You are given n queries in the form "xiyi". 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.

    就是给你n组数,每一组数由xi,yi组成,对于每一组数,求出在xi的因子中有多少个因子不是前y组数xj的因子;

    分析:

    更新每一个出现过的因子的最近的位置;

    代码:

    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    #include<queue>
    #include<deque>
    #define MOD 1000000000;
    //#define DEBUG  //todo
    using namespace std;    int nn;
    int ans;
    int n,x,y,f[110000],cnt=0;
    
    void ini()
    {
        cnt=0;
        cin>>n;
    }
    void work()
    {
        int temp;
        for(int i=1;i<=n;i++){
            cin>>x>>y;
            temp=sqrt(x);
            cnt=0;
            for(int j=1;j<=temp;j++){
                if(x%j==0){
                    if(i-f[j]>y){
                        cnt++;
                    }
                    if(i-f[x/j]>y && j!=x/j){
                        cnt++;
                    }
                    f[j]=i; f[x/j]=i;
                }
            }
            cout<<cnt<<endl;
        }
    }
    int main()
    {
        ini();
        work();
    #ifdef DEBUG
        cin>>nn;
    #endif
        return 0;
    }
  • 相关阅读:
    C语言编程练习4:镂空三角形
    C语言编程练习3:小明的18岁生日
    C语言编程练习2:放大的X
    C语言编程练习1:打印数字图形
    Hexo+Github搭建个人博客
    报表
    唐人街探案
    窗体
    ACCESS SQL
    交叉表
  • 原文地址:https://www.cnblogs.com/au-xiaotian/p/3460454.html
Copyright © 2011-2022 走看看