码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 112D Petya and Divisors 模拟题(水

时间:2014-09-05 16:09:51      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   ar   for   div   sp   on   amp   

题目链接:点击打开链接

论科学暴力的姿势重要性。。



#include <cstdio>
#include <iostream>
#include <string.h>
#include <math.h>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
#define ll int
#define N 100010
#define M 100010

vector<int>G[N], go[N];
int n, a[N], b[N], siz[N];
int main(){
    int i, j, u, v, k;
    for(i = 1; i <= 100000; i++) {
        G[i].clear();
        j = sqrt((double)i);
        for(u = 1; u <= j; u++) if(i%u==0){
            G[i].push_back(u);
            if(u != (i/u))G[i].push_back(i/u);
        }
    }
    scanf("%d",&n);
    for(i = 1; i <= n; i++)
    {
        scanf("%d %d", &a[i], &b[i]);
        for(j = 0; j < G[a[i]].size(); j++)
        {
            go[G[a[i]][j]].push_back(i);
        }
    }
    for(i = 1; i <= n; i++)
    {
        if(b[i] == 0) { printf("%d\n", G[a[i]].size());continue;}
        int ans = G[a[i]].size();
        for(j = 0; j < G[a[i]].size(); j++) {
            int l = i-b[i], r = i-1;
            l = lower_bound(go[G[a[i]][j]].begin(), go[G[a[i]][j]].end(), l) - go[G[a[i]][j]].begin();
            r = upper_bound(go[G[a[i]][j]].begin(), go[G[a[i]][j]].end(), r) - go[G[a[i]][j]].begin() -1;
            if(r - l +1 >0)ans--;
        }
        printf("%d\n", ans);
    }
    return 0;
}


CodeForces 112D Petya and Divisors 模拟题(水

标签:http   os   io   ar   for   div   sp   on   amp   

原文地址:http://blog.csdn.net/qq574857122/article/details/39081929

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!