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

PASS486|数论|约数|枚举

时间:2019-02-05 23:57:20      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:har   getc   clu   div   pac   space   png   img   目录   

PASS486|数论|约数|枚举

Problem

技术图片

分析

超级大水题,而且时间给的还是5s(???),书上给的难度还是中(???)。

枚举倍数base,枚举每个数i,每次增加base,枚举到的i的个数就+1。

Code

#include <cstdio>
#include <iostream>
using namespace std;
void read(int &n){
    int num=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        num=num*10+ch-'0';
        ch=getchar();
    }
    n=num*w;
}
const int maxn=1e7+5;
int c,n,s,e,k,num[maxn];
void init(){
    for(int base=1;base<=maxn;base++)//枚举倍数 
        for(int i=base;i<=maxn;i+=base)
            num[i]++;
}
int main(){
    init();
    read(c);
    while(c--){
        read(n);read(s);read(e);
        k=0;
        for(s;s<=e;s++) if(num[s]==n) k++;
        printf("%d\n",k);
    }
    return 0;
}

PASS486|数论|约数|枚举

标签:har   getc   clu   div   pac   space   png   img   目录   

原文地址:https://www.cnblogs.com/saitoasuka/p/10353315.html

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