Pupu

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

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
 
o(︶︿︶)o 唉,好不容易想到方法的,,,居然超时了,
 
思路:我们可以将此题用二进制的思想来解题。0代表不透明,1代表透明。
2层: (0 0)->(1 0)->(0 1)三天
3层:(0 0 0)->(1 0 0)-> (0 1 0)->(1 1 0)->(0 0 1) 五天
所以题意就转变为求2的n-1次方%n。
可是刚刚开始做的时候超时了,要对2的n-1次方这个步骤进行优化,就过了- -||
 
/*超时。。。。呜呜
#include <stdio.h>
int main()
{
__int64 n,m,i,j,a;
while(scanf("%I64d",&n),n)
{
m=n-1;
a=2;
for(i=1;i<m;)
{
if(i*2<=m)
{
a=a*a%n;
i=i*2;
}
else
{
a=a*2%n;
i++;
}
}
printf("%I64d\n",(a+1)%n);
}
return 0;
}*/

优化后的代码。。。

#include<stdio.h>
int main()
{
__int64 n,m,i,k,a,bit[];
while(scanf("%I64d",&n),n)
{
a=;
k=;
m=n-;
while(m)
{
bit[k++]=m%;//判断奇偶
m=m>>;//m/=2;
}
for(i=k-;i>=;i--)
{
a=a*a%n;
if(bit[i]==)
a=a*%n;
}
printf("%d\n",(a+)%n);
}
return ;
}

Pupu(hdu3003)数论的更多相关文章

  1. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  2. NOIP2014 uoj20解方程 数论(同余)

    又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...

  3. 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)

    ~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...

  4. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  5. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  6. bzoj2219: 数论之神

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  8. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  9. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

随机推荐

  1. Unity相机跟随-----根据速度设置偏移量

    这里假设在水中的船,船有惯性,在不添加前进动力的情况下会继续移动,但是船身是可以360度自由旋转,当船的运动速度在船的前方的时候,相机会根据向前的速度的大小,设置相机的偏移量,从而提高游戏的动态带感. ...

  2. 【转】C#中virtual和abstract的区别

    virtual和abstract都是用来修饰父类的,通过覆盖父类的定义,让子类重新定义. 它们有一个共同点:如果用来修饰方法,前面必须添加public,要不然就会出现编译错误:虚拟方法或抽象方法是不能 ...

  3. Color the ball(HDU1556)树状数组

    每次对区间内气球进行一次染色,求n次操作后后所有气球染色次数. 树状数组,上下区间更新都可以,差别不大. 1.对于[x,y]区间,对第x-1位减1,第y位加1,之后向上统计 #include<b ...

  4. 改变您的HTTP服务器的缺省banner

    (以下方法仅针对 IIS Asp.net) 服务器扫描发现漏洞,其中一个是: 可通过HTTP获取远端WWW服务信息 [Microsoft-IIS/8.5] 漏洞描述 本插件检测远端HTTP Serve ...

  5. flask_json数据入库Mongo

    首先我们先导入python内置的json库,用来将接送数据转换为python对象 import json #导入自定义的数据公共库 from db_tool import db #载入库之前先清空数据 ...

  6. 将python打包为.exe文件

    第一步:在https://pypi.python.org/pypi/PyInstaller/2.1 下载pyinstaller. 第二步:解压缩,在该目录下命令行中执行python setup.py ...

  7. [工具]渗透神器CobaltStrike 3.1.2 K8去后门破解版 & Windows版TeamServer

    CS简介 Cobalt Strike(简称CS)是全球黑客公认一款非常优秀的渗透测试神器,以metasploit为基础的GUI的框架式渗透工具,集成了传统远控功能(远程桌面VNC.键盘记录.CmdSh ...

  8. 在matlab中实现线性回归和logistic回归

    本文主要讲解在matlab中实现Linear Regression和Logistic Regression的代码,并不涉及公式推导.具体的计算公式和推导,相关的机器学习文章和视频一大堆,推荐看Andr ...

  9. pcm原始数据绘制

    最近帮别人做了个东西,这里分享一下pcm原始数据绘图的思路 1.pcm数据采样位数,根据采样位数选取适合自己绘图的采样点的数量 2.计算出最大最小的的采样点的值差 3.根据要显示pcm数据的控件宽高, ...

  10. JAVA框架之Hibernate【Hibernate缓存详解】

    1.缓存介绍 Hibernate中提供了两级Cache,第一级别的缓存是Session级别的缓存,它是属于事务范围的缓存.这一级别的缓存由hibernate管理的,一般情况下无需进行干预:第二级别的缓 ...