• Aladdin and the Flying Carpet (LightOJ


    Aladdin and the Flying Carpet (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}.
    

    Input

    Input starts with an integer T (≤ 4000), denoting the number of test cases.
    
    Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.
    

    Output

    For each case, print the case number and the number of possible carpets.
    

    Sample Input

    2
    
    10 2
    
    12 2
    

    Sample Output

    Case 1: 1
    
    Case 2: 2
    

    题意

    给定(a, b), (a)


    解析


    通过代码

    /*
    Problem
        LightOJ - 1341
    Status
    	Accepted
    Time
    	359ms
    Memory
    	6968kB
    Length
    	1607
    Lang
    	C++
    Submitted
    	2019-11-25 21:51:33
    RemoteRunId
    	1640797
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    const int MAXN = 1e6 + 50;
    
    bool vis[MAXN];
    int prime[MAXN], cnt = 0;
    
    inline ll read()    //快读,加快程序输入速度.
    {
        ll res = 0;
        char ch;
    
        ch = getchar();
    
        while(!isdigit(ch))
            ch = getchar();
    
        while(isdigit(ch)){
            res = (res << 3) + (res << 1) + ch - 48;
    
            ch = getchar();
        }
    
        return res;
    }
    
    void get_prime()     //欧拉筛,先找到sqrt(n)以内的质数,方便之后质因数分解.
    {
        vis[1] =  1;
        for(int i = 2; i <= int(1e6 + 5); i ++){
            if(!vis[i])
                prime[++ cnt] = i;
    
            for(int j = 1; j <= cnt && i * prime[j] <= int(1e6 + 5); j ++){
                vis[i * prime[j]] = 1;
                if(i % prime[j] == 0)
                    break;
            }
        }
        return ;
    }
    
    int main()
    {
        get_prime();
    
        int times, _case = 0;
    
        scanf("%d", &times);
    
        while(times --){
            ll a, b, t;
            ll ans = 1;
    
            a = read(), b = read();
            t = a;
    
            if(b * b >= a){              //如果最小的因数都超过了sqrt(a),那么说明不存在符合条件的成对的因数了.
                printf("Case %d: 0
    ", ++_case);
                continue;
            }
            
            for(int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= a; i ++){
                if(a % prime[i] == 0){
                    int res = 0;
                    while(a % prime[i] == 0){
                        res ++;
                        a /= prime[i];
                    }
    
                    ans *= 1ll * (res + 1);
                }
            }
            if(a > 1)
                ans <<= 1;
                
            ans >>= 1;    //问有几对,两个因数算作一对.(如果是完全平方数的sqrt(a)因子,则不能算作一对.)
            
            for(ll i = 1; i < b; i ++){
                if(t % i == 0)
                    ans --;
            }
            printf("Case %d: %lld
    ", ++ _case, ans);
        }
        return 0;
    }
    
    

  • 相关阅读:
    安卓环境配置
    [转载]MinGW安装过程
    [转载]解决Android studio新建项目慢的问题
    [转载]图文详解YUV420数据格式
    视频专家之路【四】:ffmpeg简单实战之获取属性
    视频专家之路【三】:Vs开发环境的搭建
    视频专家之路【二】:ffmpeg工具的使用
    视频专家之路【一】:音视频入门知识基础
    二值信号量和互斥锁到底有什么区别?
    【python标准库模块五】Xml模块学习
  • 原文地址:https://www.cnblogs.com/satchelpp/p/11941141.html
Copyright © 2020-2023  润新知