2019牛客ACM暑期多校第五场

A-digits 2

 

题目描述

You are given a positive integer n which is at most 100.

Please find a positive integer satisfying the following conditions:

1. The sum of all digits of this number is dividable by n.

2. This number is also dividable by n.

3. This number contains no more than 10410^4104 digits.
 

If such an integer doesn't exist, output "Impossible" (without quotation marks).

If there are multiple such integers, please output any one.

输入描述:

The first line contains one integer T indicating that there are T tests.

Each test consists an integer n in a single line.

* 1≤T≤1001 \le T \le 1001≤T≤100

* 1≤n≤1001 \le n \le 1001≤n≤100

输出描述:

For each query, output one line containing the answer. The number you print cannot have leading zeros. If there are multiple answers, you can print any. If such an integer doesn't exist, output "Impossible" (without quotation marks) in a single line.

示例1

输入

复制

3
1
9
12

输出

复制

1
666666
888

说明

For the last test, 888 is dividable by 12 (888 = 12 * 74) and 8 + 8 + 8 = 24 is also dividable by 12 (24 = 12 * 2).

题意:找到一个数是n的倍数&&这个数的所有数位之和是n的倍数

输出n个n(特判)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            cout<<n;
        cout<<'\n';
    }
    return 0;
}

B-generator 1 矩阵快速幂(以10为单位倍增)

 

题目描述

You are given four positive integers x0,x1,a,bx_0, x_1, a, bx0​,x1​,a,b. And you know xi=a⋅xi−1+b⋅xi−2x_i = a \cdot x_{i-1} + b \cdot x_{i-2}xi​=a⋅xi−1​+b⋅xi−2​ for all i≥2i \ge 2i≥2.

Given two positive integers n, and MOD, please calculate xnx_nxn​ modulo MOD.

Does the problem look simple? Surprise! The value of n may have many many digits!

输入描述:

The input contains two lines.
The first line contains four integers x0,x1,a,bx_0, x_1, a, bx0​,x1​,a,b (1≤x0,x1,a,b≤1091 \le x_0, x_1, a, b \le 10^91≤x0​,x1​,a,b≤109).
The second line contains two integers n, MOD (1≤n<10(106),109<MOD≤2×1091 \le n < 10^{(10^6)}, 10^9 < MOD \le 2 \times 10^91≤n<10(106),109<MOD≤2×109, n has no leading zero).

输出描述:

Print one integer representing the answer.

示例1

输入

复制

1 1 1 1
10 1000000001

输出

复制

89

说明

The resulting sequence x is Fibonacci sequence. The 11-th item is 89.

示例2

输入

复制

1315 521 20185 5452831
9999999999999999999999999999999999999 1000000007

输出

复制

914730061

题意:给出f(0),f(1),a,b,n,mod   f(n)=a*f(n-1)+b*f(n-2)    求f(n)%mod

给了2s,显然用矩阵快速幂  学习一下:矩阵快速幂 &&  转移矩阵的推导

注意要以10为单位倍增,具体见注释

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll a0,a1,p,q,mod;

struct mat///2阶
{
    ll a[2][2];
};

mat mat_mul(mat x,mat y)///矩阵相乘
{
    mat res;
    memset(res.a,0,sizeof(res.a));
    for(int i=0; i<2; i++)
        for(int j=0; j<2; j++)
            for(int k=0; k<2; k++)
                res.a[i][j]=(res.a[i][j]+(x.a[i][k]*y.a[k][j])%mod)%mod;
    return res;
}

mat mat_pow(mat x,ll n)
{
    if(n==1)
        return x;
    mat res;
    memset(res.a,0,sizeof(res.a));
    for(int i=0; i<2; i++)///{1 0} 单位阵
        res.a[i][i]=1;    ///{0 1}
    while(n)///快速幂
    {
        if(n&1)
            res=mat_mul(res,x);
        x=mat_mul(x,x);
        n>>=1;
    }
    return res;
//    return ((a0*res.a[0][0])%mod+(a1*res.a[0][1])%mod)%mod;///第一行和初始列矩阵{f(0),f(1)}的乘积==结果
}

int main()
{
    string s;
    while(scanf("%lld%lld%lld%lld",&a0,&a1,&p,&q)!=EOF)
    {
//        getchar();
        cin>>s>>mod;
        ll len=s.size();
        mat ans,c;
        memset(c.a,0,sizeof(c.a));
        memset(ans.a,0,sizeof(ans.a));
        c.a[0][0]=p;            ///转移矩阵 {p q}
        c.a[0][1]=q;            ///        {1 0}
        c.a[1][0]=1;
        ans.a[0][0]=ans.a[1][1]=1;///单位阵
        for(ll i=len-1; i>=0; i--)///从个位开始向前 每位对应转移矩阵的多少次方
        {
            ll tmp=s[i]-'0';
            if(tmp!=0)
                ans=mat_mul(ans,mat_pow(c,tmp));///pow过程中c不变
            c=mat_pow(c,10);///转移矩阵倍增 1次方 10次方 100次方……
        }
        cout<<((ans.a[1][0]*a1)%mod+(ans.a[1][1]*a0)%mod)%mod<<'\n';///乘了n个转移矩阵{f(n+1)}==(c^n)*{f(1)}
                                                                    ///                { f(n)}        {f(0)}
    }
    return 0;
}

 

全部评论

相关推荐

hanliu:1. 排版与格式问题字体与对齐问题:标题和内容的字体大小差异不够明显,无法迅速吸引目光。某些文字看起来有些拥挤(比如校园经历中的“班委成员”部分)。2. 内容逻辑性模块顺序问题:实习经历放在较靠后的位置,实际上这部分内容对应聘来说更重要,建议提前突出。细节表述不够突出:比如教育背景部分的专业课程仅仅列出名字,没有说明自己在这些课程中表现如何或者掌握了什么技能,缺乏量化描述。多余内容:例如“班委成员”和“宣传委员”这类校园经历,叙述过于普通,缺乏和岗位相关的实质性贡献。,建议简写。3. 措辞专业性表达不够精准:例如“协助班长与团支书更好地为同学服务”显得较为笼统,没有实际成果的体现。用词重复:如“学习了焊接”“学习了光检”等重复词语较多,缺乏丰富的动词来展示个人能力(如“负责”“优化”“改进”等)。技能展示不足:虽然列出了UG和CAD证书,但没有明确提到这些技能如何在实际工作中发挥作用。4. 技能匹配度技能深度不足:虽然列出了掌握的软件和技术,但没有描述技能水平(如“熟练掌握”“精通”),也没有具体案例支持这些技能。缺乏岗位导向性:比如针对机械设计与制造方向,实习经历提到了“E6尾灯项目”,但没有详细说明自己在其中的技术贡献,可能会显得经验描述泛泛而谈。5. 自我评价问题表达空泛:如“具有良好的沟通协调能力”“责任心强”之类的描述太常见,没有让人眼前一亮的特点。缺乏成果支持:自我评价中的能力没有用具体项目、经历或成就来验证,可信度较弱。 兄弟加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务