100分TLE
查看原帖
100分TLE
577836
Iverson_sun楼主2023/4/30 10:09
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<list>
using namespace std;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
#define LL long long

LL n , mod;
struct node{
	LL p[3][3];
	node(){
		memset(p , 0 , sizeof(p));
	}
};
node operator * (const node &a , const node &b){
	node c;
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			for(int k = 0 ; k < 3 ; k++){
				c.p[i][j] = (c.p[i][j] + (a.p[i][k] * b.p[k][j]) % mod) % mod;
			}
		}
	}
	return c;
}
LL s[30];
node power(node t , LL b){
	node c;
	c.p[0][0] = c.p[1][1] = c.p[2][2] = 1;
	while(b){
		if(b & 1){
			c = c * t;
		}
		t = t * t;
		b >>= 1;
	}
	return c;
}

int main(){
	cin >> n >> mod;
	s[0] = 1;
	for(int i = 1 ; i <= 18 ; i++){
		s[i] = s[i - 1] * 10;
	}
	node a , b;
	b.p[0][2] = 1 , b.p[0][1] = 1;
	a.p[1][0] = a.p[1][1] = a.p[2][1] = a.p[2][2] = 1;
	for(LL i = 1 , temp ;  ; i++){
		a.p[0][0] = s[i] % mod;
		temp = min(n , s[i] - 1) - s[i - 1] + 1;
		b = b * power(a , temp);
		if(s[i] - 1 >= n){
			break;
		}
	}
	cout << (b.p[0][0]) % mod << endl;
	return 0;
}
2023/4/30 10:09
加载中...