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;
    }
    
  • 相关阅读:
    log4j日志格式化
    日志级别是如何工作?
    Java拦截过滤器模式
    js实现图片轮播
    js实现表格的增删改查
    企业外贸网站建设的要求及注意事项
    逛知乎才知网站建设不只有wordpress建站系统,小白值得收藏
    三款适用于企业建站的CMS建站系统
    前端开发常用的网站整理
    网站建设教程:虚拟主机如何安装PageAdmin建站系统
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11846249.html
Copyright © 2011-2022 走看看