QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607758#8339. Rooted TreeSYeaseAC ✓1126ms3728kbC++172.2kb2024-10-03 16:08:522024-10-03 16:08:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 16:08:52]
  • 评测
  • 测评结果:AC
  • 用时:1126ms
  • 内存:3728kb
  • [2024-10-03 16:08:52]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <unordered_map>
#include <set>
#include <cmath>
#include <unordered_set>
#include <iomanip>
#include <stdio.h>
#include <queue>
#define int long long
//#define int __int128
using namespace std;
#define endl '\n'
#define F first
#define S second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
const int N = 1e6 + 10;
const int mod = 1e9+9;
const int M = 8;
const int MAXN = 1e6;

//读入
inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch > '9' || ch < '0') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
//打印
inline void write(int x) {
	if (x < 0) { putchar('-'); x = -x; }
	if (x > 9)write(x / 10);
	putchar(x % 10 + '0');
}

ll ksm(ll m,ll k,ll mod)
{
	ll ans=1;
	ll t=m;//通过t来预处理m的二次方幂
	while(k){
		if(k&1) ans=ans*t%mod;//判断k的二进制末位是否为1,相当于k%=2
		t=t*t%mod;//预处理
		k>>=1;//将k的二进制位右移相当于k/=2
	}
	return ans;
}

int phi(int a)
{
	int res=a;
	for(int i=2;i<=a/i;i++){
		if(a%i==0){
			res = res/i*(i-1);
			while(a%i==0) a/=i;
		}
	}
	if(a>1) res = res / a * (a - 1);
	return res;
}

void exgcd(int a,int b,int &x,int &y)
{
	if(b==0){
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,y,x);//由于是使用指针传输,故可以在这里就交换x,y
	y-=(a/b)*x;//x,y已交换
}

int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}

vector<int> a;
map<int,int> mp;
vector<int> ans;

void solve()
{
	int m,k;
	cin>>m>>k;
	int num=1;
	int sum=0;
	int ans=0;
	int ping=0;
	for(int i=1;i<=k;i++){
		ans=(ans+(ping+1)*m)%mod;
		sum=(((sum-ping)+(ping+1)*m)%mod+mod)%mod;
		num=(num+m-1)%mod;
		ping=sum*ksm(num,mod-2,mod)%mod;
	}
	cout<<ans<<endl;
}

signed main()
{
	std::ios::sync_with_stdio(false);//
	std::cin.tie(0);
	int tc;	
	//fac_init(mod);
	tc = 1;
	//cin >> tc;
	//scanf("%lld",&tc);
	while (tc--) {
		solve();
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3720kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 70ms
memory: 3724kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 755ms
memory: 3604kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 821ms
memory: 3664kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 462ms
memory: 3660kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 1115ms
memory: 3724kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 203ms
memory: 3728kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 610ms
memory: 3584kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

score: 0
Accepted
time: 357ms
memory: 3724kb

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 329ms
memory: 3684kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 969ms
memory: 3608kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 1126ms
memory: 3664kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 1126ms
memory: 3672kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 1122ms
memory: 3608kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed