HDOJ Pupu 3003【快速幂】
来源:互联网 发布:碧欧泉的奇迹水 知乎 编辑:程序博客网 时间:2024/05/16 05:51
Pupu
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1409 Accepted Submission(s): 539
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?
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
230
Sample Output
12
Source
2009 Multi-University Training Contest 11 - Host by HRBEU
Recommend
gaojie | We have carefully selected several similar problems for you: 3001 3004 3002 3007 3006
题目大意:
一种动物有n层皮肤,每层皮肤都有两种状态,透明或者不透明,透明的皮肤光照一天变为不透明,不透明的皮肤光照一天变为透明
光可以透过透明的皮肤照射到下一层。 刚出生的动物所有层的皮肤都是不透明的,每层皮肤都变过透明,则这只动物长大成人。(特别注意是变过,,而不是所有成都一起变透明)
问,给定一个N,表示N层皮肤,问第几天可以长大成人,得数MOD上N、
题解:
可以先推前几个数。得出2,3,5,9.。。可以推算出公式 2^(n-1) + 1 结果 mod n 就是一个快速幂
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;typedef long long ll;ll fun(ll x,ll n,ll modn){ll res=1;while(n>0){if(n&1) res=res*x%modn;x=x*x%modn;n>>=1;}return res;}int main(){int n;while(scanf("%d",&n),n){printf("%lld\n",fun(2,(ll)(n-1),n)+1);}return 0;}
0 0
- HDOJ Pupu 3003【快速幂】
- HDU - 3003 - Pupu(快速幂)
- HDOJ 题目3003Pupu(数学,(n^e)%m的快速求法)
- 杭电 3003 Pupu(快速幂取余)
- HDU - 3003 - Pupu (快速幂取模!)
- hdu 3003 pupu ( (题目易混淆概念、详解) 二分快速幂 )
- HDU3003 Pupu,快速幂取模
- Pupu(快速幂取模)
- hdu3003 Pupu 快速幂取模
- 快速幂取模——Pupu(HDU 3003)
- HDU 3003 Pupu
- hdu 3003 Pupu
- hdu 3003 Pupu
- HDU——3003 Pupu
- HDOJ 1061快速幂
- HDOJ-----1097简单快速幂
- HDU 3003 PuPu(N非常大 语死早)
- hdoj 4038 Stone(贪心+快速幂)
- Android开发中EditText小技巧之如何设置光标颜色及粗细
- Android Fragment 生命周
- android 读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)
- Android中多线程处理
- 改变与适应
- HDOJ Pupu 3003【快速幂】
- 队列
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
- python用于测试的failIf,failUnless
- 网络编程系列之一 mysql
- 工作日志-4
- 在 ASP.NET 网页中显示动态生成的图片
- 在 Linux 操作系统中使用 Nginx 运行 ASP.NET 4
- DDMS - Dalvik Debug Monitor Service