HDU 5241 Friends
来源:互联网 发布:java数字图像处理 pdf 编辑:程序博客网 时间:2024/06/11 13:55
HDU 5241 Friends
各种语言相互独立
故而答案是2的乘方
由样例可知是32的n次方
剩下的是一个大数乘法
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;const int N=9999;const int DLEN=4;class BigNum{private: int a[40000]; int len;public: BigNum() { len=1; memset(a,0,sizeof(a)); } BigNum(const int b) { int c,d=b; len=0; memset(a,0,sizeof(a)); while(d>N) { c=d%(N+1); d=d/(N+1); a[len++]=c; } a[len++]=d; } BigNum operator*(const BigNum &T)const { BigNum ret; int i,j,up; int temp,temp1; for(i=0; i<len; ++i) { up=0; for(j=0; j<T.len; ++j) { temp=a[i]*T.a[j]+ret.a[i+j]+up; if(temp>N) { temp1=temp%(N+1); up=temp/(N+1); ret.a[i+j]=temp1; } else { up=0; ret.a[i+j]=temp; } } if(up!=0)ret.a[i+j]=up; } ret.len=i+j; while(ret.a[ret.len-1]==0&&ret.len>1)--ret.len; return ret; } void print() { int i; printf("%d",a[len-1]); for(i=len-2; i>=0; --i) { printf("%.4d",a[i]); } printf("\n"); }};int main(){ int n,T,Case=1; scanf("%d",&T); while(T--) { scanf("%d",&n); BigNum a(32),ans(1); while(n>0) { if(n&1) ans=ans*a; if(n==0) break; a=a*a; n=n>>1; } printf("Case #%d: ",Case++); ans.print(); } return 0;}
阅读全文
0 0
- HDU 5241 - Friends
- HDU 5241 Friends
- HDU 5241 Friends
- HDU 5241 Friends
- HDU 5241 Friends
- HDU 5241 Friends (数学)
- [数学 高精度] HDU 5241 Friends
- HDU 5241 - Friends <高精度 + Java>
- HDU-Friends
- Friends (HDU
- HDU 5241 Friends(大数+快速幂)
- Hdu 5241 Friends【规律+高精度乘法】
- hdu 3172 Virtual Friends
- hdu 3172 Virtual Friends
- hdu 3172:Virtual Friends
- hdu 3172 Virtual Friends
- hdu 3172 Virtual Friends
- HDU 3172 Virtual Friends
- java基础系列(二)
- framebuffer的驱动框架
- 写作的乐趣
- SQL Server2005实现累加
- JavaScript(2)
- HDU 5241 Friends
- Unity3D
- Centos下安装MySQL
- 从零开始实现遗传算法(用遗传算法求解函数的最大值)
- 分布式开放消息系统(RocketMQ)的原理与实践
- 08-CSS的定位
- 期末考试 编程题#8:计算整数k(Coursera 程序设计与算法 专项课程3 C++程序设计 郭炜、刘家瑛;进制转换)
- openlayer 图形交互编辑
- HTTP协议