Summing up Powers LightOJ - 1132

Given N and K, you have to find

(1K + 2K + 3K + ... + NK) % 232

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case contains two integers N (1 ≤ N ≤ 1015) and K (0 ≤ K ≤ 50) in a single line.

Output

For each case, print the case number and the result.

Sample Input

3

3 1

4 2

3 3

Sample Output

Case 1: 6

Case 2: 30

Case 3: 36

题意 : 给出n,k. 要你算出1-n的k次方的和。
n小于10的15次方 数据范围很大 结合题意,可以推出需要用矩阵快速幂。
这里写图片描述
太菜了太菜了,这题写了整整半天,还是在看了题解情况下。

#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<math.h>
#include<deque>
#include<set>
#include<functional>
using namespace std;
const long long MAX=(long long)1<<32;// 初始化一定要这样写,不然是(int)1<<32  直接溢出.
class mat
{
public:
    int sz;
    long long m[55][55];
    mat(int sz){
        memset(m,0,sizeof m);
        this->sz=sz;
    }
    mat(){memset(m,0,sizeof m);}
    mat operator * (mat a)
    {
        mat cnt(sz);
        for(int i=1;i<=sz;i++)
        {
            for(int j=1;j<=sz;j++)
            {
                for(int k=1;k<=sz;k++)
                    cnt.m[i][j]+=(m[i][k]*a.m[k][j])%MAX;
            }
        }
        return cnt;
    }
};
mat E;
void init(int sz)
{
    memset(E.m,0,sizeof E.m);
    E.sz=sz+2;
    for(int i=0;i<=55;i++)
    {
        E.m[i][sz+2]=1;
        E.m[i][i]=1;
    }
    //杨辉三角初始化
    for(int i=sz;i>=2;i--)
    {
        for(int j=sz+2;j>=i;j--)
        {
            E.m[i][j]=E.m[i+1][j+1]+E.m[i+1][j];

        }
    }
    //第一排单独初始化
    for(int i=0;i<55;i++)
        if(E.m[2][i])
            E.m[1][i]=E.m[2][i];
}
mat pow(mat b,long long k)
{
    mat res=mat(b.sz);
    for(int i=0;i<=res.sz+2;i++)
    {
        res.m[i][i]=1;
    }
    while(k)
    {
        if(k&1) res=res*b;
        b=b*b;
        k>>=1;
    }
    return res;
}
mat getQ(int sz)
{
    mat ans=mat(sz+2);
    for(int i=1;i<=sz+2;++i)
    {
        ans.m[i][1]=1;
    }
    return ans;
}
int main()
{
    int T;
    int ca=1;
    scanf("%d",&T);
    while(T--)
    {
        long long n;
        long long k;
        scanf("%lld%lld",&n,&k);
        init(k);
        if(k==0)
        {
            printf("Case %d: %u\n",ca++,n);
            continue;
        }
        mat ans=pow(E,n-1)*getQ(k);
        printf("Case %d: %lld\n",ca++,ans.m[1][1]%MAX);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 设计sigma-delta转换器是一个复杂的过程,需要经过多个步骤。以下是在MATLAB / Simulink中设计sigma-delta转换器的一般过程: 1. 确定系统规格:首先,确定sigma-delta转换器的采样率、精度要求和输入输出范围等系统规格。 2. 模型建立:使用Simulink建立sigma-delta转换器的模型。该模型包括一个Σ(summing)节点、一个Δ(differential)节点和一个比较器节点。使用研究成果相关的数学模型,可以更准确地描述转换器的行为。 3. 参数选择:选择适当的参数来满足系统规格。包括选择合适的阶数和过采样率。过采样率越高,转换器的性能越好,但同时也会增加计算的复杂性和系统复杂度。 4. 仿真验证:使用Simulink对模型进行仿真验证。这可以帮助我们了解系统的性能如何受到不同参数选取的影响。 5. 优化调整:根据仿真结果,对转换器的参数和结构进行优化调整。例如,可以调整Σ节点和Δ节点之间的连接方式,或者优化误差补偿电路的设计。 6. 输出结果:根据优化后的模型,输出设计好的sigma-delta转换器的结果。这可以包括模型中各个节点和参数的数值值。 此外,在设计sigma-delta转换器的过程中,还需要考虑一些其他的因素,如抗噪声能力、计算要求、电路复杂度和成本等。根据具体的需求和约束条件,可以对上述过程进行调整和扩展,以获得最佳的设计结果。 总而言之,设计sigma-delta转换器需要经历模型建立、参数选择、仿真验证、优化调整和输出结果等多个步骤。通过这些步骤,可以获得一个满足系统要求的优化转换器设计。 ### 回答2: Sigma-delta (ΣΔ) converters are commonly used in analog-to-digital (ADC) and digital-to-analog (DAC) applications. They are known for their outstanding performance in terms of resolution, noise shaping, and dynamic range. To design a Sigma-delta converter in MATLAB/Simulink, we can follow the following steps: 1. Specify the converter's specifications: Determine the required resolution, sampling frequency, and input signal bandwidth to meet the desired performance requirements. 2. Model the Sigma-delta modulator: Create a Simulink model to represent the Sigma-delta modulator. This can be done by using Simulink blocks such as Adders, Delays, and Comparators. 3. Define the Analog-to-Digital Converter (ADC): Add the ADC block to the Simulink model and configure its parameters, such as the number of bits, input range, and sampling frequency. 4. Implement the digital decimation filter: Insert a digital decimation filter after the ADC block to remove out-of-band noise and further improve the overall performance. The decimation filter can be modeled using filter blocks in Simulink. 5. Evaluate the performance: Simulate the Simulink model with different input signals and study the system's response. Analyze the output waveform, signal-to-noise ratio (SNR), and other performance metrics to assess the design's effectiveness. 6. Optimize the design: Based on the performance analysis, make design adjustments to enhance the overall system's performance. This can involve modifying filter parameters, changing the modulator architecture, or adjusting the decimation filter design. 7. Verify the design: Validate the design by testing it with various input signals and comparing the simulation results with the desired specifications. 8. Implement the design: Once the design is finalized, the Sigma-delta converter can be implemented in hardware using appropriate components. In summary, to design a Sigma-delta converter in MATLAB/Simulink, we start by specifying the converter's specifications, modeling the modulator and ADC in Simulink, adding a digital decimation filter, evaluating the performance, optimizing the design, verifying the design, and finally implementing it in hardware.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值