hdu2521 反素数(求约数个数)

来源:互联网 发布:select to SQL 编辑:程序博客网 时间:2024/06/08 14:41


http://acm.hdu.edu.cn/showproblem.php?pid=2521

题意:不解释。


思路:本来想看下反素数,范围太大的没什么思路,这题是求约数个数(其实是1~n-1范围内的约数个数,也不能叫约数了),只不过范围比较小,暴力解决。


好久没水,水一下应该没人打我吧。。


#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;typedef long long ll;const int N = 5010;const int INF = 0x3f3f3f3f;int num[N];void table(){    memset(num, 0, sizeof(num));    for(int i = 1; i <= N; i++)    {        for(int j = 1; j <= (i/2+1); j++)        {            if(i%j == 0) num[i]++;        }    }}int main(){  //  freopen("in.txt", "r", stdin);    table();    int n, a, b, ans, maxx;    scanf("%d", &n);    while(n--)    {        maxx = -INF;        scanf("%d%d", &a, &b);        for(int i = a; i <= b; i++)            maxx = max(maxx, num[i]);        for(int i = a; i <= b; i++)            if(num[i] == maxx)            {                ans = i;                break;            }        printf("%d\n", ans);    }    return 0;}


0 0
原创粉丝点击