# [第一波模拟\day2\T1] {病毒分裂}(split.cpp)

## 【题目描述】

A 学校的实验室新研制出了一种十分厉害的病毒。由于这种病毒太难以人工制造

## 【输出】

5 3 7 6

2 6 23 8

## 【数据范围及提示】

1 ~ 5
P 是质数
1 < K, N, P < 10000
6 ~ 7 1 < N < 10^18
8 ~ 10 P不是质数1 < K , P < 2^31

## 【解法】

80分，乱搞+利用数据

#include <stdio.h>
#include <string.h>
#define maxbuff 1<<20
#define ll long long
#define set_file(File) freopen(File".in", "r", stdin), freopen(File".out", "w", stdout)
#define close_file() fclose(stdin), fclose(stdout)
char buff[maxbuff], *iter = buff;
template<class Type> inline void read(register Type &x)
{
x = 0;
while(*iter < '0' || *iter > '9') ++iter;
while(*iter >= '0' && *iter <= '9') x = x * 10 + *iter++ - '0';
}
ll k, n, mo, ans;
ll inv(ll n, ll p)
{
ll ret = 1;
for(ll i = p; i; i >>= 1, n = (n * n) % mo)
if(i & 1) ret = (ret * n) % mo;
return ret;
}
ll pow(ll n, ll t)
{
ll ret = 1;
for(; t; t >>= 1, n = (n * n) % mo)
if(t & 1) ret = (ret * n) % mo;
return ret;
}
int main()
{
set_file("split");
ans = pow(k, n - 1) - 1;
if(ans < 0) ans += mo;
ans = (ans * inv(k - 1, mo - 2)) % mo;
printf("%I64d\n", ans);
close_file();
return 0;
}

100分，一种不是很协调的方法。直接考虑保留分母的因子，也就是将mod数乘上个分母，之后加个快速乘加速

#include <stdio.h>
#include <string.h>
#define maxbuff 1<<20
#define ll long long
#define set_file(File) freopen(File".in", "r", stdin), freopen(File".out", "w", stdout)
#define close_file() fclose(stdin), fclose(stdout)
char buff[maxbuff], *iter = buff;
template<class Type> inline void read(register Type &x)
{
x = 0;
while(*iter < '0' || *iter > '9') ++iter;
while(*iter >= '0' && *iter <= '9') x = x * 10 + *iter++ - '0';
}
ll k, n, mo, ans, P;
ll mul(ll x, ll y)
{
ll ret = 0;
for(; y; y >>= 1, x = (x + x) % P)
if(y & 1) ret = (ret + x) % P;
return ret;
}
ll pow(ll n, ll t)
{
ll ret = 1;
for(; t; t >>= 1, n = mul(n, n))
if(t & 1) ret = mul(ret, n);
return ret;
}
int main()
{
set_file("split");