zoukankan      html  css  js  c++  java
  • Aladdin and the Flying Carpet LightOJ

    题意:

    就是求a的因数中大于b的有几对

    解析;

    先把素数打表

    运用算术基本定理 求出a的所有因数的个数

    然后减去小于b的因数的个数

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define maxn 1100000
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
    LL primes[maxn];
    bool vis[maxn];
    LL ans = 0;
    void init()
    {
        mem(vis,0);
        for(int i=2; i<maxn; i++)
            if(!vis[i])
            {
                primes[ans++] = i;
                for(LL j=(LL)i*i; j<maxn; j+=i)
                    vis[j] = 1;
            }
    }
    int main()
    {
        init();
        int T, kase = 0;
        scanf("%d",&T);
        LL a, b;
        while(T--)
        {
            LL res = 1;
            scanf("%lld%lld",&a,&b);
            if(a <= b*b)  {printf("Case %d: 0
    ",++kase);continue;}
            LL x = a;
            for(LL i=0; i<ans && primes[i] * primes[i] <= a; i++)
            {
                LL cnt2 = 0;
                while(a % primes[i] == 0)
                {
                    a /= primes[i];
                    cnt2++;
                }
                if(cnt2 > 0)
                {
                    res *= (cnt2 + 1);
    //                if(primes[i] < b)
    //                    ios *= (cnt2+1);
                }    
            }
            if(a > 1)
            {
                res *= 2;
    //            if(a < b)
    //                ios *= 2;
            }
            res /= 2;
            for(int i=1; i<b; i++)
                if(x % i == 0)
                    res--;
            printf("Case %d: %lld
    ",++kase,res);
            
        }    
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    JavaScript中的面向对象
    操作文件
    PDO 数据访问抽象层
    Jquery事件
    Jquery
    面向对象的五大基本原则是
    ioc依赖注入的原则
    java3
    java基础2
    java基础
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9187113.html
Copyright © 2011-2022 走看看