Aladdin and the Flying Carpet (算术基本定理)

题目:

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}.

1、我先直接分的,就感觉肯定没这么简单,果然tel了。。。
2、于是找答案,发现要用算术基本原理,自己真的什么都不懂= =

(1)一个大于1的正整数N,如果它的标准分解式为: 这里写图片描述
那么它的正因数个数为这里写图片描述

3、学到了在一定范围内找素数较快的方法,大概是要两个数组,一个用来记录哪些是素数(prim),一个用来判断(vis),就是先把vis初始化为0,将i从2开始,vis[2]是0,于是prim[0]=2,于是将2的倍数在vis中都变为1,3、5、7….可同理。总之就是去掉每个素数的倍数,剩下的一定是素数。ps.里面的c最后就是范围内的素数总个数,在之后还是有点用的

    ```
    void prime()
    { 
        memset(vis, 0, sizeof(vis));
        for(i=2; i<=maxn; i++){
            if(!vis[i]){
            prim[c++]=i;
            for(j=2*i; j<=maxn; j+=i)
                vis[j]=1;
            }
        }
    }
    ```

还有我必须表示一下,在写完这个提交后还re了两次,最后发现我把j+=i写成了j++,下次不能这样了啊!!!
4、最后用公式得到的是所有正因数的个数,所以要除2,还要去掉在1到给出的最小因数中出现的因数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值