美文网首页
hdoj3003 Pupu

hdoj3003 Pupu

作者: 科学旅行者 | 来源:发表于2016-08-06 16:45 被阅读10次

题目:

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

说一下我的理解:
这种动物总共有两种类型的皮肤:透明&不透明,不透明的皮肤被太阳晒一整天就可以变成透明的,阳光可以透过透明的皮肤进入内部(因为有多层皮肤)。透明的皮肤晒一整天后就会变成不透明的,并且会隔绝接下来一天的阳光。当所有的皮肤都变过一次透明的(初始所有的皮肤都不是透明的),这只动物也就长大了。问一只n层皮肤的动物经过多少天才能长大。

题意懂了就可以根据数据推出公式: (2的n-1次方+1) % n.

参考代码:

#include <iostream>
#include <cstdio>
typedef long long ll;
using namespace std;
ll n;
ll quickmod(ll a,ll b,ll mod) {//快速幂;
    ll res = 1;
    a = a % mod;
    while (b > 0) {
        if (b & 1) {
            res = res * a % mod;
        }
        b = b / 2;
        a = a * a % mod;
    }
    return res;
}
int main() {
    while (scanf("%lld", &n) != EOF && n) {
        ll a = 2;
        ll res = quickmod(a,n-1,n);
        ll ans = (res + 1 % n) % n;
        printf("%lld\n", ans);
    }
    return 0;
}

相关文章

  • hdoj3003 Pupu

    题目: Problem DescriptionThere is an island called PiLiPaLa...

  • go排序之路(编程基础)

    对python排序有兴趣的可以去我之前的博客查找TopGun Python排序 冒泡排序 pupu.go(思路 每...

  • 开源, 一种全新的创业模式,正在悄然袭来

    | 作者:王暄 | 转载自:PUPU Talk |编辑:王玥敏 | 设计:刘颖洁 开源社引言 开源是一种新的开发模...

  • 国庆假期总结

    国庆假期休息日具体事项 一、妈妈(10.1-10.3休息3天) 10月1日:跟女儿交流不平和,与pupu谈话才知道...

  • 过生日把家里锅具全部用上了!哈哈哈

    今天是我的生日,昨晚23:00我点的pupu的菜送到了。赶紧收拾吧,毛豆剪了角便于入味。花生太脏,有黄泥,洗了十多...

  • 2019.2.17

    小妞假期最后半天 终于带她去了说了好久的Pupu熊展 粉是可爱的小熊 怎么引导她不是所有可爱的小东西都能扑倒在怀里...

  • 育儿中的困惑及解答

    pupu跟我普及了关于青少年青春期的一些知识,还跟我谈到孩子成长期父亲角色的重要性。 如果前6岁前跟孩子的关系不好...

  • 过去的那些年。

    一点钟关电脑 在一天最热的时候睡觉 房间太安静 甚至可以听到手臂关节处 血液流动时候 pupu的声音。不清楚什么时...

  • 小小弹珠,留给你的思考

    2017-06-20 努力原创的 pupu家的快乐数学 在一个房间内,有若干个一模一样的盒子排成一排放在桌子上,小...

  • 多抓鱼

    第一次知道多抓鱼的名字,貌似是3月份,Pupu告诉我的,说是一个很有爱的平台,专门做二手书流通的。 那时我们组成了...

网友评论

      本文标题:hdoj3003 Pupu

      本文链接:https://www.haomeiwen.com/subject/afiksttx.html