题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3003

Pupu

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

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

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--天数  规律      结果

1---2    2^0+1      0

2---3    2^1+1       1

3---5    2^2+1        2

4---9    2^3+1       1

规律就是

注意:一入long long 深似海

This is the code

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
inline int read()//输入外挂
{int ret=0, flag=0;char ch;if((ch=getchar())=='-')flag=1;else if(ch>='0'&&ch<='9')ret = ch - '0';while((ch=getchar())>='0'&&ch<='9')ret=ret*10+(ch-'0');return flag ? -ret : ret;
}
LL quick_mod(LL x,LL n,LL mod)
{LL ret=1;while(n){if(n&1)ret=ret*x%mod;x=x*x%mod;n>>=1;}return ret;
}
int main()
{//freopen("D:\\chnegxubianji\\inORout\\in.txt", "r", stdin);//freopen("D:\\chnegxubianji\\inORout\\out.txt", "w", stdout);LL n;while(scanf("%lld",&n)&&n){printf("%lld\n",(quick_mod(2,n-1,n)+1)%n);}return 0;
}

hdu 3003-Pupu-快速幂取模相关推荐

  1. 快速幂取模——Pupu(HDU 3003)

    题目: 由题目推出计算公式: ans = (2^(n-1) + 1) % n 因为n取值很大,所以需要用到快速幂取模: int multi(int a,int b) { int ret; ret=1; ...

  2. HDU3003 Pupu,快速幂取模

    快速幂取模就是在O(logn)内求出a^n mod b的值.算法的原理是(a*b) mod c=(a mod c)*(b mod c)mod c /************************** ...

  3. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  4. HDU 4365 正方形格子涂色中心对称轴对称的涂法有多少种-思维-(矩阵坐标关系快速幂取模)

    题意:n*n的格子,涂色,有k种颜料,必须满足旋转任意个90度和翻转之后图片的样子不变,现在已经有m个格子涂过色了,问还有多少种涂法满足上述条件. 分析: 满足上述对称条件,那么涂色的种类问题我们可以 ...

  5. c语言的幂乘积表达式,POJ 1845 Sumdiv [素数分解 快速幂取模 二分求和等比数列]

    大致题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题基础: 1) 整数的唯一分解定理: 任意正整数都有且只有一种方式写出其素因子的乘积表达式. ,其中 为素数 2) 约数和 ...

  6. C语言快速幂取模算法小结

    资料链接:http://www.jb51.net/article/54947.htm C语言实现的快速幂取模算法,是比较常见的算法.分享给大家供大家参考之用.具体如下: 首先,所谓的快速幂,实际上是快 ...

  7. 【算法分析与设计】快速幂算法与快速幂取模算法

    文章目录 快速幂算法 算法分析 算法实现 位运算优化 BigInteger支持 快速幂取模算法 算法优点 算法推导 算法实现 BigInteger支持 本文完整代码实现(Java语言描述) 快速幂算法 ...

  8. CodeForces Round #191 (327C) - Magic Five 等比数列求和的快速幂取模

    很久以前做过此类问题..就因为太久了..这题想了很久想不出..卡在推出等比的求和公式,有除法运算,无法快速幂取模... 看到了 http://blog.csdn.net/yangshuolll/art ...

  9. 【快速幂取模】NOI 7833:幂的末尾

    NOI 7833:幂的末尾     点击打开链接 总时间限制: 1000ms 内存限制: 65536kB 描述 幂ab的末3位数是多少? 输入 两个正整数a,b.1 <= a <= 100 ...

  10. 【算法】求n的m次方(快速幂取模)

    题目 求n的m次方,n,m均为自然数. 解析 看似简单的题目,但是要想写的高效还不是那么容易想出来. 实现 unsigned int power(unsigned int a, unsigned in ...

最新文章

  1. 【怎样写代码】复杂对象的组装与创建 -- 建造者模式(三):建造者模式
  2. PHP的函数-----生成随机数、日期时间函数
  3. 一步步解析Attention is All You Need
  4. 新概念英语(1-11)Is this your shirt ?
  5. 查看、启动、关闭防火墙
  6. mysql密码修改无效后,修改方法
  7. solr获取同义词 java_如何在使用缩写及其全名搜索时使solr同义词获取相同的结果(相同的数字和顺序)...
  8. JAVA我的世界怎么弄TNT大陆_《我的世界》爷爷的遗言:TNT大陆地图存档
  9. 如何在edge浏览器上安装flash插件运行需要flash的游戏
  10. rust服务器人数查询网站,Rust Web框架列表
  11. Typora怎么将文本居中
  12. Python L型组件填图问题(棋盘覆盖问题)
  13. vmware服务器文件备份,三种VMware数据备份和恢复方法
  14. windows系统镜像修复计算机,电脑映像损坏怎么修复_windows提示损坏的映像怎么处理...
  15. 宋第一状元宰相吕蒙正三赋
  16. Tensorflow.js||使用 CNN 识别手写数字
  17. uva11689 Soda Surpler
  18. 分析QQ微信使用的是UDP还是TCP协议
  19. Java教程:Jasper-pdf打印类
  20. 换发型软件有哪些?试试这些软件吧

热门文章

  1. 离散行业和流程行业的区别
  2. Hive SQL 小表与大表Join 原理与实操
  3. 《机器学习实战》源代码和数据集下载
  4. 复选框的全选反选实现(即购物车的复选框实现)
  5. florr 花瓣讲解(半完成)
  6. 21 世纪什么最贵?那必须得是“人才”啊,一本书带你读懂 TCP-IP 协议
  7. Linux和Win10双系统出现GUN GRUB解决方法
  8. 腾讯云SDK使用python版
  9. Rockchip3066 修改开机 LOGO 和开机动画
  10. 合天——SQL注入实验二