F题,可以帮我看看吗?一直150分,还有段错误,但是不知道在哪里呀

#include<bits/stdc++.h>
using namespace std;
#define inf 1e18
#define endl '\n'
#define int long long
typedef  long long ll;
typedef pair<int,int> pii;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ksm(int base,int p,int mod){
	int res=1;
	while(p){
		if(p&1) res=res*base%mod;
		base=base*base%mod;
		p>>=1;
	}
	return res;
}
void solve(){
	int base,c0,mod;
	cin >> base >> c0 >> mod;
	if(mod==1){
		int q;cin >> q;
		while(q--){
			cout << 0 << endl;
		}
		return;
	}
	vector<int> vis(mod*2+1,0);
	int cs=-1,ce=-1,cur_sum=0,cur_c=c0;
	vector<int> sum(1,0);
	//首先生成一个c
	int cnt=0;
	while(1){
		cur_c=ksm(base,cur_c,mod);
		if(vis[cur_c]){
			cs=vis[cur_c];
			ce=cnt;
			break;
		}
		cnt++;
		cur_sum=(cur_sum+cur_c)%mod;
		sum.push_back(cur_sum);
		vis[cur_c]=cnt;
	}
	int pre=sum[cs-1];
	int len=ce-cs+1;
	int tot=(sum[ce]-sum[cs-1]+mod)%mod;
	int q;cin >> q;
	while(q--){
		int k;cin >> k;
		if(k<=ce){
			cout << sum[k] << endl;
		}else{
			int cycle_time=(k-cs+1)/len%mod;
			int rem=(k-cs+1)%len;
			int ans=((pre+cycle_time*tot%mod)%mod+(sum[cs+rem-1]-pre+mod)%mod)%mod;
			cout << ans << endl;
		}
	}
}
/*

*/
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t=1;
//	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

红完了呀F题。

全部评论
可以看看题解 https://ac.nowcoder.com/discuss/1522251
点赞 回复 分享
发布于 07-23 10:55 北京

相关推荐

07-23 12:04
门头沟学院 Java
现在是很缺人吗
码农索隆:缺分母,不缺分子,这样好作为炫耀的资本
点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务