HDU 3003 Pupu
来源:互联网 发布:源代码java教学视频 编辑:程序博客网 时间:2024/05/22 02:18
Pupu
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 21 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
思路:容易得出公式(pow(2,n-1)+1)%n;然后是快速幂取模。。。
AC代码:
#include <cstdio>using namespace std;long long pow_mod(long long a,long long b,long long m){ long long t=1; while(b) { if(b&1) t=t*a%m; a=a*a%m; b>>=1; } return t;}int main(){ int n; while(scanf("%d",&n)!=EOF,n) { long long res=0; res=(pow_mod(2,n-1,n)+1)%n; printf("%lld\n",res); } return 0;}
- HDU 3003 Pupu
- hdu 3003 Pupu
- hdu 3003 Pupu
- HDU——3003 Pupu
- HDU - 3003 - Pupu (快速幂取模!)
- HDU - 3003 - Pupu(快速幂)
- 快速幂取模——Pupu(HDU 3003)
- HDU 3003 PuPu(N非常大 语死早)
- HDOJ Pupu 3003【快速幂】
- hdu 3003 pupu ( (题目易混淆概念、详解) 二分快速幂 )
- 杭电 3003 Pupu(快速幂取余)
- HDOJ 题目3003Pupu(数学,(n^e)%m的快速求法)
- HDU3003 Pupu,快速幂取模
- Pupu(hdu3003)数论
- Pupu(快速幂取模)
- hdu3003 Pupu 快速幂取模
- HDU 3003
- hdu 3003 背包
- 国内HTML5前端开发框架汇总
- 在 Visual Studio 中使用 mdk 编译 ARM 程序
- samba进程
- 转:不同的行业和工作的真实情况是怎样的?
- C++利用new_handler()函数处理异常
- HDU 3003 Pupu
- 存储过程,怕忘,先留下来
- 单内核OS与微内核OS结构比较
- 自己动手,制作inline hook扫描工具
- glMatrixMode()函数和glLoadIdentity()函数
- L4Linux的版本比较
- 10年跳槽经验总结 高级人才不用找工作
- jdk与jre的区别
- PHP创建文件(夹)以及目录操作