bzoj3662

数学

其实我们发现不用每个数都去试一下,只要确定每个数字有几个就可以确定这个数。所以我们先搜索一下,然后检验。

但是这样太慢了,所以我们打表。

打出1-30的结果,然后取模。

打表的程序好像弄丢了。。。就是要各种高精度

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll ans, p;
string s[] = {
"0",
"0",
"245025",
"38118276",
"0",
"701565254721",
"0",
"13517018740330137",
"1054861758265199049",
"234734126209968566538",
"7470486567228198747024",
"3655529240602979286948564",
"74706976586522786987307024",
"53025203348958311874492027381",
"1055707679026725117872959265049",
"729803650696038636028778345751783",
"17225329259435286208202532321097545",
"10392367448990719529019739012358123154",
"272006553269189557898804980767500371746",
"130396873127602647877846824219825388617972",
"4028460591965088771059406847405053201371772",
"1603523894497218565486191724343889231534702375",
"64657520623442242466249906292826929365340923553",
"19343435636436705194168806046639915495855042504403",
"769302689915124392250215975265042038457944892036471",
"239684534506691040208694761530735879121194094879875543",
"10791152002373774986609529818052463359685665383236441042",
"2896176361911385189942286704606894921646831443702777412148",
"134581880579217016257787571305079497004703413686681117431540",
"34269736053164528543199304278101128211432125247436707468636178"};
int main()
{
    scanf("%d%lld", &n, &p);
    for(int i = 0; i < s[n - 1].length(); ++i)
        ans = (ans * 10 + s[n - 1][i] - '0') % p;
    printf("%lld\n", ans);
    return 0;
}
View Code

 

posted @ 2017-06-22 17:25  19992147  阅读(168)  评论(0编辑  收藏  举报