• LightOJ


    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的因子对,最小值不能小于b。

    思路:根据算术基本原理(1)

    (1)一个大于1的正整数N,如果它的标准分解式为: ,那么它的正因数个数为  。
    (2) 它的全体正因数之和为  。
     时就称N为完全数。 是否存在奇完全数,是一个至今未解决之猜想。
    (3) 利用算术基本定理可以重新定义整数a和b的最大公因子  和最小公倍数  , 并证明  。

    所以可以求出 a 的因子除以2,再减掉小于b的因子数,就是答案。

    #include<map>
    #include<stack>
    #include<queue>
    #include<math.h>
    #include<vector>
    #include<string>
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #define mem(a,b) memset(a,b,sizeof(a))
    #define maxn 1100000
    #define mod 1000000007
    #define ll long long
    #define inf 0x3f3f3f3f
    using namespace std;
    ll tot;
    bool vis[maxn+5];
    int p[maxn+5];
    void getp(){
        tot=0;
        for(ll i=2;i<=maxn;i++)vis[i]=true;
        for(ll i=2;i<=maxn;i++)if(vis[i]){
            p[tot++]=i;for(ll j=i*i;j<=maxn;j+=i)vis[j]=false;
        }
    }
    ll fac(ll n){
       if(n==0)return 0;
       ll ans=1;
       for(int i=0;i<tot;i++){
        if(n<p[i])break;
            if(n%p[i]==0){
                ll s=0;while(n%p[i]==0){s++;n/=p[i];};
                ans*=(s+1);
            }
       }
       if(n!=1)ans*=2;
       return ans;
    }
    int main(){
        getp();
        int t,test=0;
        scanf("%d",&t);
        while(t--){
            ll a,b,ans=0,c=0;
            scanf("%lld%lld",&a,&b);
            if(b>=sqrt(a*1.0))ans=0;
            else{
                for(ll i=1;i<b;i++)
                    if(a%i==0)c++;
                ans=fac(a)/2-c;
            }
            printf("Case %d: %lld
    ",++test,ans);
        }
    }

  • 相关阅读:
    T4设计时模板调试
    MVC开发T4代码生成之一文本模板基础
    经典选项卡
    IE 调试工具 Utilu IE Collection:IE5.5、6.0、7.0, 8.0…各版本浏览器兼容性测试工具
    滚动读行!
    自定义标签的用法、支持IE6
    jQuery 参数传递例子
    IMG在IE6下不能HOVER的解决办法!
    点击渐变弹出层
    操作滚动条滚动到指定位置
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053231.html
Copyright © 2020-2023  润新知