2^100%100=?

fztfztfzt 2014-10-19 06:37:32
求2^100%100=?
有没有什么好方法?
...全文
268 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
shizhong_q 2014-10-21
  • 打赏
  • 举报
回复
引用 3 楼 zxh707wk 的回复:
#include <stdio.h>

int function()
{
    int i;
    int temp=1;
    for(i=0;i<100;i++)
        temp=(temp*2)%100;
    return temp;
}

int main()
{
    printf("%d\n",function());
    return 0;
}
仅供参考
可是答案是i对的, 不知道为什么啊。 我刚学C。 能把具体思路给我说一下吗 详细一点 谢谢!
shizhong_q 2014-10-21
  • 打赏
  • 举报
回复
引用 3 楼 zxh707wk 的回复:
#include <stdio.h>

int function()
{
    int i;
    int temp=1;
    for(i=0;i<100;i++)
        temp=(temp*2)%100;
    return temp;
}

int main()
{
    printf("%d\n",function());
    return 0;
}
仅供参考
这个是不是 错了啊? 在循环第5次时候 temp = 2^6 = 64 第六次: temp = (2^7)%100 = 28 第七次: temp = (28*2)%100=56 到这儿就错了啊。 没有保证 括号里直接叠加到 2^100 次方 。
hhyocean 2014-10-21
  • 打赏
  • 举报
回复
引用 8 楼 DelphiGuy 的回复:
2^100=16^25=16^12*16^13 所以:2^100%100=(16^12%100 * 16^13%100)%100,int64可以直接计算。
707wk 2014-10-21
  • 打赏
  • 举报
回复
引用 13 楼 shizhong_q 的回复:
[quote=引用 3 楼 zxh707wk 的回复:]
#include <stdio.h>

int function()
{
    int i;
    int temp=1;
    for(i=0;i<100;i++)
        temp=(temp*2)%100;
    return temp;
}

int main()
{
    printf("%d\n",function());
    return 0;
}
仅供参考
可是答案是i对的, 不知道为什么啊。 我刚学C。 能把具体思路给我说一下吗 详细一点 谢谢![/quote]只是要个位和十位的数,所以只保留这两位的数就行了
阿麦 2014-10-20
  • 打赏
  • 举报
回复
2^100%100 = (2^10^10)%100 = 1024^10^100 = 24^10 % 100 = 24^2^5^100=76^5%100=76
  • 打赏
  • 举报
回复
实际上这题用int都可以计算:((16^5%100)^5)%100
  • 打赏
  • 举报
回复
2^100=16^25=16^12*16^13 所以:2^100%100=(16^12%100 * 16^13%100)%100,int64可以直接计算。
nice_cxf 2014-10-20
  • 打赏
  • 举报
回复
100本身就不大,根本用不到快速幂取模,还可以简化下:2^100=1024^10,顺序循环求24^10就是了
帅气小小少 2014-10-20
  • 打赏
  • 举报
回复
引用 2 楼 u012061345 的回复:
快速幂取模,可以在对数时间解决。很基本的算法。
Mark下, 学习了!
mylsf 2014-10-20
  • 打赏
  • 举报
回复
?你就没次乘以2都对100取余,高位是多少不用关心
老王爱上猫 2014-10-20
  • 打赏
  • 举报
回复
本帖子已过去太久远了,不再提供回复功能。
707wk 2014-10-19
  • 打赏
  • 举报
回复
#include <stdio.h>

int function()
{
    int i;
    int temp=1;
    for(i=0;i<100;i++)
        temp=(temp*2)%100;
    return temp;
}

int main()
{
    printf("%d\n",function());
    return 0;
}
仅供参考
罗博士 2014-10-19
  • 打赏
  • 举报
回复
快速幂取模,可以在对数时间解决。很基本的算法。
learner66 2014-10-19
  • 打赏
  • 举报
回复
这个可以用递归,或者你直接用math头文件,里面有幂函数。

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧