Submission #16886573


Source Code Expand

// Problem : E - Sequence Sum
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ`
ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、
ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 
ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	ll N;
	int X,M;
	cin>>N>>X>>M;
	ll val=X,sum=0;
	vi m(M+1);
	vl sm(M+1);
	FOR(x,1,N+1)
	{
		m[val]=x;
		sum+=val;
		sm[x]=sum;
		val=(val*val)%M;
		ll cpy=val;
		if(val==0)
		{
			cout<<sum<<nl;
			return 0;
		}
		if(val==1)
		{
			cout<<sum+N-x;
			return 0;
		}
		if(m[val])
		{
			N-=x;//?
			ll quo=N/(x-m[val]+1);//?
			N%=x-m[val]+1;
			sum+=(sm[x]-sm[m[val]-1])*quo;//?
			break;
		}
	}
	while(N-->0)//?
	{
		sum+=val;
		val=(val*val)%M;
	}
	cout<<sum;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Submission Info

Submission Time
Task E - Sequence Sum
User amarnathsama
Language C++ (GCC 9.2.1)
Score 0
Code Size 2591 Byte
Status WA
Exec Time 12 ms
Memory 4556 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:79:6: warning: unused variable ‘cpy’ [-Wunused-variable]
   79 |   ll cpy=val;
      |      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 23
WA × 1
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, max_01.txt, max_02.txt, max_03.txt, max_11.txt, max_12.txt, max_13.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3656 KiB
hand_02.txt AC 3 ms 3508 KiB
hand_03.txt AC 4 ms 4484 KiB
hand_04.txt AC 5 ms 4480 KiB
hand_05.txt WA 8 ms 4476 KiB
max_01.txt AC 6 ms 4456 KiB
max_02.txt AC 8 ms 4556 KiB
max_03.txt AC 12 ms 4452 KiB
max_11.txt AC 6 ms 4484 KiB
max_12.txt AC 3 ms 4480 KiB
max_13.txt AC 7 ms 4416 KiB
random_01.txt AC 6 ms 3644 KiB
random_02.txt AC 4 ms 3720 KiB
random_03.txt AC 5 ms 4180 KiB
random_04.txt AC 3 ms 3604 KiB
random_05.txt AC 3 ms 3672 KiB
random_06.txt AC 3 ms 3744 KiB
random_07.txt AC 5 ms 4184 KiB
random_08.txt AC 5 ms 4196 KiB
random_09.txt AC 5 ms 3716 KiB
random_10.txt AC 5 ms 4012 KiB
sample_01.txt AC 2 ms 3616 KiB
sample_02.txt AC 3 ms 3612 KiB
sample_03.txt AC 6 ms 4480 KiB