UVA 10523 VERY EASY!!!

Most of the times, the students of Computer Science & Engineering of BUET deal with bogus, tough and
very complex formulae. That is why, sometimes, even for a easy problem they think very hard and make
the problem much complex to solve. But, the team members of the team “BUET PESSIMISTIC”
are the only exceptions. Just like the opposite manner, they treat every hard problem as easy and so
cannot do well in any contest. Today, they try to solve a series but fail for treating it as hard. Let
them help.
Input
Just try to determine the answer for the following series

N
i=1
iAi
You are given the value of integers N and A (1 ≤ N ≤ 150, 0 ≤ A ≤ 15).
Output
For each line of the input, your correct program should output the integer value of the sum in separate
lines for each pair of values of N and A.
Sample Input
3 3
4 4
Sample Output
102
1252

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include <iterator>
#include <stdlib.h>

using namespace std;

typedef unsigned long long ULL;

const int N=500;

struct node
{
    int num[N];
    int cnt;
}a,b;

int muti(int k)
{
    for(int i=0;i<a.cnt;i++)
        a.num[i]*=k;
    int i;
    for(i=0;i<a.cnt;i++)
    {
        a.num[i+1]+=a.num[i]/10;
        a.num[i]%=10;
    }
    //剩余之后
    while(a.num[i])
    {
        a.num[i+1]+=a.num[i]/10;
        a.num[i]%=10;
        i++;
    }
    //去零
    while(i>=0&&!a.num[i]) i--;
    a.cnt=i+1;
}

node add(node a,node b)
{
    node temp;
    memset(temp.num,0,sizeof(temp.num));
    temp.cnt=0;
    for(int i=0,j=0,g=0;;i++,j++)
    {
        if(g==0&&i>=a.cnt&&j>=b.cnt) break;
        int t=g;
        if(i<a.cnt) t+=a.num[i];
        if(j<b.cnt) t+=b.num[i];
        temp.num[temp.cnt++]=t%10;
        g=t/10;
    }
    return temp;
}

int main()
{
    int N,A;
    while(scanf("%d%d",&N,&A)!=EOF)
    {
        if(A==0)
        {
            printf("0\n");
            continue;
        }
        memset(a.num,0,sizeof(a.num));
        memset(b.num,0,sizeof(b.num));
        b.cnt=a.cnt=0;
        for(int i=1;i<=N;i++)
        {
            memset(a.num,0,sizeof(a.num));
            a.cnt=1,a.num[0]=1;
            for(int j=1;j<=i;j++)
                muti(A);
            muti(i);
            b=add(a,b);
        }
        for(int i=b.cnt-1;i>=0;i--)
            printf("%d",b.num[i]);
        printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值