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;
    }
    
  • 相关阅读:
    etcd基本操作
    使用docker配置etcd集群
    etcd启用https服务
    etcd3集群管理
    Opengl绘制我们的小屋(一)球体,立方体绘制
    OpenGL 用三角形模拟生成球面
    PDFSharp生成PDF.
    OpenXml操作Word的一些操作总结.无word组件生成word.
    F# 图形数学基础。
    SQL Server (MSSQLSERVER) 服务因 2148081668 服务性错误而停止。
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11846249.html
Copyright © 2011-2022 走看看