• E


     

    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

    题目大意 就是给你一个面积N和一个可能的最小边m,问你满足条件的组合有多少个(不能是正方形)

    题解:先求出a的因子的个数,然后暴力求出小与b而且是a的因子的个数,然后再减去就行了。对于这个题,边的最小值为b,所以如果b*b>=a的话,那么一定无解。若有解那么b<=sqrt(a)所以b的范围要小于1e6,但是t的范围是4e3,时间复杂度大约是o(bt)=4e10。明显不行.....,但是百度上都这么做的,可能是数据有点水吧~。

    using namespace std;
    typedef long long ll;
    const ll N=1e6+60;
    const ll MAX=1e6+50;
    bool primes[N];
    ll pre[N];
    ll pos=0;
    void inint(){
        primes[1]=1;
        primes[2]=0;
        for(ll i=2;i<=MAX;i++){
            if(!primes[i]) pre[++pos]=i;
            for(ll j=1;j<=pos&&i*pre[j]<=MAX;j++){
                primes[i*pre[j]]=1;
                if(i%pre[j]==0) break;
            }
        }
    }
    void solve(ll time){
        ll a,b;
        scanf("%lld%lld",&a,&b);
        ll m=a;
        if(b*b>=a) {
            printf("Case %d: 0
    ",time);
            return ;
        }
        ll ans=1;
        for(ll i=1;i<=pos;i++){
            if(pre[i]>a) break;
            if(a%pre[i]==0){
                ll p=0;
                while(a%pre[i]==0) {
                    a/=pre[i];p++;
                }
                ans*=((ll)1+p);
            }
        }
        if(a!=1) ans*=(ll)2; 
        ans/=(ll)2;
        for(ll i=1;i<b;i++) if(m%i==0) ans--;
        printf("Case %d: %lld
    ",time,ans);
    }
    int main(){
        int t;
        inint();
        scanf("%d",&t);
        for(int i=1;i<=t;i++) solve(i);
        return 0;
     } 

      

  • 相关阅读:
    GridView 应用貌似是个mm写的,值得尊敬!
    .net 时间函数
    .net 获取url的方法
    SaveGraphics
    asp网站页面上都是问号
    由于编码方式导致CSS样式表失效
    .net url乱码
    常用正则表达式
    解决realse版在加载toolbar后不正常退出的现象
    general error c1010070: Failed to load and parse the manifest
  • 原文地址:https://www.cnblogs.com/Accepting/p/11343265.html
Copyright © 2020-2023  润新知