SGU 374 题解
来源:互联网 发布:网络推广是长久工作吗 编辑:程序博客网 时间:2024/05/05 18:47
题目连接http://acm.sgu.ru/problem.php?contest=0&problem=374
题目要求(a*x+b)的k次幂的所有系数的和。
此题由于1<=a,b<=100,1<=k<=20;则要用到高精度。
long long的最大值:9223372036854775807(19位)
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161
本题解题的依据:(a*x+b)的k次幂的系数和等价于设x=1;求(a+b)的k次幂;
代码如下:
#include<stdio.h>#include<string.h>char a[1010];char b[1010];char c[1010];void deal(char *a,char *b){ int lena=strlen(a); int lenb=strlen(b); int len; memset(c,'0',sizeof(c)); int i,j,t; for(i=0;i<lena;i++){ int arr=0; for(j=0;j<lenb;j++){ t=(c[i+j]-'0')+(a[i]-'0')*(b[j]-'0')+arr; c[i+j]=t%10+'0'; arr=t/10; } if(arr!=0){ c[i+j]=arr+'0'; } } for(i=1009;i>=0;i--){ if(c[i]!='0') break; } memset(b,0,sizeof(b)); len=i+1; for(i=0;i<len;i++){ b[i]=c[i]; } b[len]=0; memset(c,0,sizeof(c));}int main(){ int a1,b1,k,i; while(~scanf("%d %d %d",&a1,&b1,&k)){ int n=a1+b1; i=0; while(n>=10){ a[i++]=n%10+'0'; n=n/10; } a[i]=n+'0'; strcpy(b,a); while(k>1){ k--; deal(a,b); } int len=strlen(b); for(i=len-1;i>=0;i--){ printf("%c",b[i]); } puts(""); }return 0;}
- SGU 374 题解
- SGU 377题解
- SGU 375题解
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU 259 单机调度问题 +贪心 及此题解法的证明
- ListActivity
- zoj1716
- seo每天做的事情
- 顺序容器
- HDU 4612 Warm up
- SGU 374 题解
- 关于u-boot中的.balignl 16,0xdeadbeef 的理解
- poj1753
- 做seo的文章到底要注意哪些 才能做到在蜘蛛眼里是美味
- 经典笔试题
- 你且快起来
- 目录(数据结构C语言)
- poj2965
- hdu 2577 How to Type