2017山东省赛B题Quadrat

题目链接

题意:
找出有多少个数,它的长度为n,且平方后对10^n取模与原来的数之间的差距不大于d(每一个数字的差距和)

思路:
对于10以内的数,如果d等于零的时候,只有四个数满足要求:0,1,5,6
如果d等于二时,有八个数满足要求:0,1,2,4,5,6,7,9
于是进行打表,先找出1<=n<=4范围内0<=d<=3的答案。
1:4 4 8 8
2:4 12 40 56
3:4 36 200 396
4:4 108 1000 2744

经观察可以发现a[i][j] =a[i-1][j]*(2*j+1);
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<cstdio>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
ll a[20][10];
void init ()
{
    a[1][0] = a[1][1] = 4;
    a[1][2] = a[1][3] = 8;
    for (ll i=2; i<=18; ++i)
        for (ll j=0; j<=3; ++j)
    {
        a[i][j] = a[i-1][j]*(2*j+1);
    }
}
int main ()
{
    init ();
    int t;
    scanf ("%d", &t);
    while (t--)
    {
        int n, m;
        scanf ("%d%d", &n, &m);
        printf ("%lld\n", a[n][m]);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值