HDU - 3003 - Pupu (快速幂取模!)
来源:互联网 发布:前端优化方法 编辑:程序博客网 时间:2024/05/22 08:08
Pupu
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1133 Accepted Submission(s): 445
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
题意:PuPu有n层皮肤,每层皮肤都有2种状态:透明和不透明,每层皮肤如果能被太阳照射到,则被太阳照射一天后都会变换状态。
PuPu在出生的时候,所有的皮肤都为不透明的,直到每一层的皮肤都有过变为透明状态的时候,PuPu也就长大了。
问有n层皮肤的PuPu几天后能长大。
思路:可以推出公式 ans = (2^(n-1) + 1)%n , 然后按照快速幂取模算出来即可(没用LL又WA了一次!)
AC代码:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <cmath>#define LL long longusing namespace std;LL qmod(LL n){LL q = 2, mo = n, ans = 1;n--;while(n){if(n&1) ans = (ans * q) % mo;q = (q%mo*q%mo)%mo;n>>=1;}return (ans+1)%mo;}int main(){LL n;while(scanf("%I64d", &n), n){printf("%I64d\n", qmod(n));}return 0;}
2 2
- HDU - 3003 - Pupu (快速幂取模!)
- 快速幂取模——Pupu(HDU 3003)
- HDU - 3003 - Pupu(快速幂)
- HDU3003 Pupu,快速幂取模
- Pupu(快速幂取模)
- hdu3003 Pupu 快速幂取模
- HDU 3003 Pupu
- hdu 3003 Pupu
- hdu 3003 Pupu
- hdu 3003 pupu ( (题目易混淆概念、详解) 二分快速幂 )
- HDOJ Pupu 3003【快速幂】
- HDU——3003 Pupu
- HDU 3003 PuPu(N非常大 语死早)
- 杭电 3003 Pupu(快速幂取余)
- HDOJ 题目3003Pupu(数学,(n^e)%m的快速求法)
- Pupu(hdu3003)数论
- hdu 3003 快速幂取模
- hdu 1601(快速幂取模)
- hibernate里面数据库查询语句mysql
- 【NOI2004】郁闷的出纳员Codevs1286
- hdu 1016 Prime Ring Problem
- 第16周项目1-数组的排序
- 软件开发工程师
- HDU - 3003 - Pupu (快速幂取模!)
- cocos2dx动画常见22种特效
- 内部排序之归并排序
- 关于iOS延时操作,阶段性总结(部分关于点击,双击事件冲突)
- Android中的getDimension,getDimensionPixelOffset和getDimensionPixelSize
- Linux cat命令
- 第十六周项目 3 用函数指针调用函数
- ubuntu之E:Could not open lock file /var/lib/dpkg/lock - open (2:No such file or direction)
- MINUS(差集)、INTERSECT(交集)和UNION (ALL)(并集)