hdu3003 Pupu 快速幂取模

Pupu

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1859    Accepted Submission(s): 732


Problem Description
There is an island called PiLiPaLa.In the island there is a wild animal living in it, and you can call them PuPu. PuPu is a kind of special animal, infant PuPus play under the sunshine, and adult PuPus hunt near the seaside. They fell happy every day.

But there is a question, when does an infant PuPu become an adult PuPu?
Aha, we already said, PuPu is a special animal. There are several skins wraping PuPu's body, and PuPu's skins are special also, they have two states, clarity and opacity. The opacity skin will become clarity skin if it absorbs sunlight a whole day, and sunshine can pass through the clarity skin and shine the inside skin; The clarity skin will become opacity, if it absorbs sunlight a whole day, and opacity skin will keep sunshine out.

when an infant PuPu was born, all of its skins were opacity, and since the day that all of a PuPu's skins has been changed from opacity to clarity, PuPu is an adult PuPu.

For example, a PuPu who has only 3 skins will become an adult PuPu after it born 5 days(What a pity! The little guy will sustain the pressure from life only 5 days old)

Now give you the number of skins belongs to a new-laid PuPu, tell me how many days later it will become an adult PuPu?
 

Input
There are many testcase, each testcase only contains one integer N, the number of skins, process until N equals 0
 

Output
Maybe an infant PuPu with 20 skins need a million days to become an adult PuPu, so you should output the result mod N
 

Sample Input
  
  
2 3 0
 

Sample Output
  
  
1 2
 

Source

那啥。。。这题是在提前知道是快速幂取模的情况莫名其妙的猜出来的规律的。。。。

因为和2^n张的太像了。。。

所以并不会推倒,哪日补上

快速幂直接上模版

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
long long n;
long long queen(long long another){
    if(another==0){
        return 1;
    }else if(another==1){
        return 2;
    }
    long long res = 0;
    res = queen(another/2)%n;
    res = (res * res)%n;
    if(another%2){
        res = (res * 2 )%n;
    }
    return res;
}
int main(){
    while (~scanf("%lld",&n)) {
        if(n==0){
            break;
        }
        long long ans = queen(n-1);
        printf("%lld\n",(ans+1)%n);
    }
    return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值