zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1341

    题意:

    It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.

    Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

    Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.

    思路:

    先将分解成质数的幂次形式,求出所有的约数,再减去小于b的约数对即可。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e6+10;
    const int MOD = 1e9+7;
    
    LL IsPrime[MAXN], Prime[MAXN];
    int tot;
    LL a, b;
    
    void Init()
    {
        memset(IsPrime, 0, sizeof(IsPrime));
        IsPrime[1] = 1;
        tot = 0;
        for (int i = 2;i < MAXN;i++)
        {
            if (IsPrime[i] == 0)
                Prime[++tot] = i;
            for (int j = 1;j <= tot && i*Prime[j] < MAXN;j++)
            {
                IsPrime[i*Prime[j]] = 1;
                if (i%Prime[j] == 0)
                    break;
            }
        }
    }
    
    int main()
    {
        Init();
        int t, cnt = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cnt);
            scanf("%lld%lld", &a, &b);
            if (b*b > a)
            {
                printf(" 0
    ");
                continue;
            }
            LL psum = 1;
            LL x = a;
            for (int i = 1;i <= tot && Prime[i] <= x;i++)
            {
                if (x%Prime[i] == 0)
                {
                    int tmp = 1;
                    while(x%Prime[i] == 0)
                    {
                        tmp++;
                        x/=Prime[i];
                    }
                    psum *= tmp;
                }
            }
            if (x>1)
                psum *= 2;
            psum /= 2;
            for (int i = 1;i < b;i++)
            {
                if (a%i == 0)
                    psum--;
            }
            printf(" %lld
    ", psum);
        }
        
        return 0;
    }
    
  • 相关阅读:
    PHP远程下载图片,微信头像存到本地,本地图片转base64
    jQuery Validate自定义错误信息,自定义方法
    创建自己的composer包
    js,JQ获取短信验证码倒计时
    JQ JS复制到剪贴板
    js,JQuery 生成二维码
    js,JQuery实现,带筛选,搜索的select
    HTML5拖放牛刀小试
    HTML5上传图片预览功能
    一次dropzone体验
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11846249.html
Copyright © 2011-2022 走看看