stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll inf=1e18;

int n;

ll ans=1;

int main(){

	ll a,b;

	string s;

	cin>>a>>s;

	b=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');

	ans=a*b;

	ans/=100;

	cout<<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

	unsigned long long a;

	string s;

	scanf("%lld",&a);

	cin>>s;

	unsigned long long x= (s[0]-'0')*100 + (s[2]-'0')*10 + (s[3]-'0'); 

	printf("%llu",x*a/100);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    unsigned long long q,z;

    double w;

    scanf("%llu %lf",&q,&w);

    w+=1e-6;

    z=w*100;

    q*=z;

    printf("%llu\n",q/100);

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
//

//	Created by shamim_nik

//



#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;



typedef long long ll;

typedef tree<int,null_type,less<int>,rb_tree_tag,

		tree_order_statistics_node_update> indexed_set;



#define br printf("\n")

#define pi acos(-1)



int main () {

	ios::sync_with_stdio(0);

	cin.tie(0);



//	freopen("input.txt", "r", stdin);

//	freopen("output.txt", "w", stdout);



	ll a;

	double b;

	cin >> a >> b;

	b *= 100;

	cout << ll((a * (ll)(round(b ))) / 100) << "\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <string>

#include <cmath>

#include <cstdlib>

#define ll long long

using namespace std;

int main()

{

	ll a;

	double b;

	scanf("%lld %lf",&a,&b);

	b=b+1e-7;

	ll c=b*100;

	ll d=c*a/100;

	printf("%lld",d);

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 1e6 + 10;



signed main() {

	// ios::sync_with_stdio(false);

	ll a, c;

	double b;

	cin >> a >> b;

	c = b * 100 + 0.1;

	cout << (ll)(a * c / 100) << '\n';

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///







#include<bits/stdc++.h>

using namespace std;





typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vl;

typedef vector<vi> vvi;

typedef vector<vl> vvl;

typedef pair<int,int> pii;

typedef pair<double, double> pdd;

typedef pair<ll, ll> pll;

typedef vector<pii> vii;

typedef vector<pll> vll;

typedef double dl;



#define endl '\n'

#define PB push_back

#define F first

#define S second

#define all(a) (a).begin(),(a).end()

#define rall(a) (a).rbegin(),(a).rend()

#define sz(x) (int)x.size()



const double PI = acos(-1);

const double eps = 1e-9;

const int inf = 2000000000;

const ll infLL = 9000000000000000000;

#define MOD 1000000007



#define mem(a,b) memset(a, b, sizeof(a) )

#define sqr(a) ((a) * (a))



#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define fraction() cout.unsetf(ios::floatfield); cout.precision(0); cout.setf(ios::fixed,ios::floatfield);

#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);



#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {			cerr << endl;}

template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}



ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }

ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }





int dx[] = { 0, 0, +1, -1, -1  +1, -1, +1 };

int dy[] = { +1, -1, 0, 0, -1, +1, +1, -1 };



int stoi ( char c ) {return c-'0';}



int main()

{

	optimize();



	ll a;

	cin >> a;



	string s;

	cin >> s;



	ll b = stoi ( s[0] ) * 10;

	b += stoi ( s[2] );

	b *= 10;

	b += ( stoi ( s[3] ) );



	a *= b;

	a /= 100;

	cout << a << endl;





	return 0;

}
































// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string.h>

#include <algorithm>

#include <cstring>

#include <math.h>

#include <map>

using namespace std;



int main()

{

	long long a;

	char s[4];

	cin>>a>>s;

	int bb =(s[0]-'0')*100 +(s[2]-'0')*10+(s[3]-'0');

	long long ans =bb*a/100;

	cout<<ans<<endl;

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

string a,b;

int dian;

char c[100],d[100],ans[100];

void mut(string a,string b){

    int la=a.length();

    int lb=b.length();

    int x=0;

    for(int i=0;i<la;i++)

        c[la-i-1]=a[i]-'0';

    for(int i=0;i<lb;i++)

        d[lb-i-1]=b[i]-'0';

    for(int i=0;i<la;i++){

        x=0;

        for(int j=0;j<lb;j++){

            ans[i+j]=ans[i+j]+x+c[i]*d[j];

            x=ans[i+j]/10;

            ans[i+j]=ans[i+j]%10;

        }

        ans[i+lb]=x;

    }

    int lc=la+lb;

    while(lc>1&&ans[lc-1]==0)

        lc--;

    if(lc<dian)

        printf("0");

    for(int i=lc-1;i>=dian;i--)

        printf("%d",ans[i]);

}

int main()

{

    cin>>a>>b;

    int lb=b.length();

    string tmp="";

    for(int i=0;i<lb;i++){

        if(i==0&&b[i]=='0')continue;

        if(b[i]!='.')

            tmp+=b[i];

        else{

            dian=lb-i-1;

        }

    }

    mut(a,tmp);

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  	long long int a,s;

	double  b;

	 scanf ("%lld",&a);

	 scanf("%lf",&b);

	s=b*100+0.001;

	s=(a*s)/100;

	 printf("%lld",s);

	 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

   long long a,s;

   double b;

   cin>>a>>b;

    s=round(b*100);

    s=(s*a)/100;

   cout<<s;

return 0;}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<math.h>

int main()

{

	long long int a,b,ans;

    double s;

	scanf("%lld %lf",&a,&s);

	b=round(s*100);

	ans=a*b/100;

	printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int c = 300000;

int main(){

   int n,b[c]={},w[c]={},ans=c;

   string s;

   cin >> n >> s;

   for(int i=0;i<n;i++){

       int flag = 0,flag1=0;

       if(s[i]=='#') flag++;

       b[i+1] = b[i] + flag;

       if(s[n-i-1]=='.') flag1++;

       w[i+1] = w[i] + flag1;

   }

   reverse(w,w+n+1);

   for(int i=0;i<=n;i++) ans = min(ans,b[i]+w[i]);

   cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

int main(){

   int n,w=0,b=0;

   string s;

   cin >> n >> s;

   for(int i=0;i<n;i++){

       if(s[i]=='.') w++;

   }

   int ans = w;

   for(int i=0;i<n;i++){

       if(s[i]=='#') b++;

       else w--;

       ans = min(ans,b+w);

   }

   cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

using namespace std;



int n, m=50000, mi;

double cx, cy, d, mx, p=1.0, x[55], y[55];

double f(double p, double q) {return p*p + q*q;}



int main() {

	int i;

	cin >> n;

	for(i=0; i<n; i++) {

		cin >> x[i] >> y[i];

		cx += x[i]; cy += y[i];

	}

	cx /= n; cy /= n;

	while(m--) {

		mx = f(cx - x[0], cy - y[0]);

		mi = 0;

		for(i=1; i<n; i++) {

			d = f(cx - x[i], cy - y[i]);

			if(d > mx) mx = d, mi = i;

		}

		cx += (x[mi] - cx) * p;

		cy += (y[mi] - cy) * p;

		p *= 0.999;

	}

	printf("%.9f", sqrt(mx));

	return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <cmath>

using namespace std;



int n, m=20000, mi;

double cx, cy, d, mx, p=1.0, x[55], y[55];

double f(double p, double q) {return p*p + q*q;}



int main() {

	int i;

	cin >> n;

	for(i=0; i<n; i++) {

		cin >> x[i] >> y[i];

		cx += x[i]; cy += y[i];

	}

	cx /= n; cy /= n;

	while(m--) {

		mx = f(cx - x[0], cy - y[0]);

		mi = 0;

		for(i=1; i<n; i++) {

			d = f(cx - x[i], cy - y[i]);

			if(d > mx) mx = d, mi = i;

		}

		cx += (x[mi] - cx) * p;

		cy += (y[mi] - cy) * p;

		p *= 0.999;

	}

	printf("%.9f", sqrt(mx));

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define fi first

#define se second



typedef pair<ll,ll> P;

using VP = vector<P>; using VVP = vector<VP>;

using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;

const long double inf=1e9+7;

const ll INF=1LL<<61;

const ll mod=1e9+7;



double x[55],y[55];

double dif(int i,int j){

  return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));

}





int main(){

  int i,j,k;

  int n;

  cin>>n;

  for(i=0;i<n;i++){

    cin>>x[i]>>y[i];

  }

  x[n]=0,y[n]=0;

  double l=500;

  while(l>1e-68){

    double md=-1;

    int ind;

    for(i=0;i<n;i++){

      if(md<dif(i,n)){

        md=dif(i,n);

        ind=i;

      }

    }

    x[n]=x[n]+l*(x[ind]-x[n])/md;

    y[n]=y[n]+l*(y[ind]-y[n])/md;

    l*=0.995;

  }

  double md=-1;

  int ind;

  for(i=0;i<n;i++){

    if(md<dif(i,n)){

        md=dif(i,n);

        ind=i;

    }

  }



  cout<<fixed<<setprecision(15)<<md<<endl;

  

  return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back

#define fi first

#define se second

typedef pair<ll,ll> P;

using VP = vector<P>; using VVP = vector<VP>;

using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;

const int inf=1e9+7;

const ll INF=1LL<<61;

const ll mod=1e9+7;



int n;

double x[1010],y[1010];



double ly,ry;



double solve(double px){

  ly=-1000.0;

  ry=2000.0;

  while(1){

    double sy=(2*ly+ry)/3.0;

    double ty=(ly+2*ry)/3.0;

    double ss,tt;

    ss=0.0,tt=0.0;

    for(int i=0;i<n;i++){

      ss=max(ss,sqrt((px-x[i])*(px-x[i])+(sy-y[i])*(sy-y[i])));

      tt=max(tt,sqrt((px-x[i])*(px-x[i])+(ty-y[i])*(ty-y[i])));

    }

    //cout<<ss<<endl;

    if(ry-ly<=1e-10) {

      //cout<<ss<<endl;

      return ss;

    }

    if(ss<=tt) ry=ty;

    else ly=sy;

  }

}



int main(){

  int i,j;

  cin>>n;

  for(i=0;i<n;i++) cin>>x[i]>>y[i];

  double lx=-1000.0,rx=2000.0;

  while(1){

    double sx=(2*lx+rx)/3.0;

    double tx=(lx+2*rx)/3.0;

    if(rx-lx<=1e-10) {

      cout<<fixed<<setprecision(15)<<solve(sx)<<endl;

      return 0;

    }

    if(solve(sx)<=solve(tx)) rx=tx;

    else lx=sx;

  }



  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

using P = pair<int,int>;

#define chmax(x,y) x = max(x,y);

#define chmin(x,y) x = min(x,y);

const int di[] = {-1, 0, 1, 0};

const int dj[] = {0, -1, 0, 1};

const int INF = 1001001001;







int main() {

    ll n, x, m;

    cin >> n >> x >> m;

    vector<ll> a;

    vector<int> q(100005);

    ll d = x;

    a.push_back(x);

    ll t = n;

    ll ans = 0;

    ll tot = 0;

    ll point = 0;

    bool ok = false;

    while (1) {

        t--;

        d = (d*d)%m;

        //cout << d << endl;

        if (d == 0) {

            rep(i,a.size()) ans += a[i];

            cout << ans << endl;

            return 0;

        }

        if (d == 1) {

            rep(i,a.size()) tot += a[i];

            ans = tot + n-ll(a.size());

            cout << ans << endl;

            return 0;

        }

        if (d == a.back()) {

            rep(i,a.size()) tot += a[i];

            ans = tot + (n-ll(a.size()))*d;

            cout << ans << endl;

            return 0;

        }

        if (q[d] == 1) {

            point = d;

            ok = true;

            break;

        }

        if (t == 0) break;

        a.push_back(d);

        q[d]++;

    }

    if (ok) {

        rep(i,a.size()) ans += a[i];

        n -= ll(a.size());

        ll po = 0;

        rep(i,a.size()) {

            if (a[i] == point) po = i;

        }

        ll loop = 0;

        for (int i = po; i < a.size(); i++) {

            loop += a[i];

        }

        ll ji = ll(a.size()) - po;

        ans += loop * (n/ji);

      n %= ji;

      for (int i = po; i <= po+n-1; i++) ans += a[i];

        cout << ans << endl;

        return 0;

    }

    if (t == 0) {

        rep(i,a.size()) ans += a[i];

    }

    else {

        ll p = a.size();

        //ll tot = 0;

        rep(i,a.size()) tot += a[i];

        ll y = n/p;

        //rep(i,y) ans += tot;

        ans += tot*y;

        n %= p;

        rep(i,n) ans += a[i];

    }

    cout << ans << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

using P = pair<int,int>;

#define chmax(x,y) x = max(x,y);

#define chmin(x,y) x = min(x,y);

const int di[] = {-1, 0, 1, 0};

const int dj[] = {0, -1, 0, 1};

const int INF = 1001001001;







int main() {

    ll n, x, m;

    cin >> n >> x >> m;

    vector<int> id(m,-1);

    vector<int> a;

    int len = 0;

    ll tot = 0;

    while (id[x] == -1) {

        a.push_back(x);

        id[x] = len;

        len++;

        tot += x;

        x = (x*x)%m;

    }



    int c = len-id[x];

    ll s = 0;

    for (int i = id[x]; i < len; i++) s += a[i];



    ll ans = 0;

    if (n <= len) {

        rep(i,n) ans += a[i];

    } else {

        ans += tot;

        n -= len;

        ans += s*(n/c);

        n %= c;

        rep(i,n) ans += a[id[x]+i];

    }

    cout << ans << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

typedef long long lint;

using namespace std;



lint n, x, m;

const lint E = 40;



lint f(lint z) {

    return z * z % m;

}



struct str {

    lint dest;

    lint sum;

    str() {}

    str(lint d, lint s) : dest(d), sum(s) {}

};



vector<vector<str>> doubling;



lint solve(int start, lint num) {

    lint now = start;

    bitset<E> b(num);

    lint res = 0;

    for (int i = 0; i < E; i++) {

        if (b[i]) {

            auto s = doubling[i][now];

            now = s.dest;

            res += s.sum;

        }

    }

    return res;

}



int main() {

    cin >> n >> x >> m;

    doubling.resize(E, vector<str>(m));

    for (int i = 0; i < m; i++) {

        doubling[0][i] = str(f(i), i);

    }

    for (int e = 1; e < E; e++) {

        for (int i = 0; i < m; i++) {

            auto first = doubling[e - 1][i];

            auto second = doubling[e - 1][first.dest];

            doubling[e][i] = str(second.dest, first.sum + second.sum);

        }

    }

    cout << solve(x, n) << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long lint;

using namespace std;



struct loop_info {

    lint loop_len;

    lint prefix_len;

    lint unit;

    loop_info() {}

    loop_info(lint l, lint p, lint u) : loop_len(l), prefix_len(p), unit(u) {}

};



lint n, x, m;



lint f(lint z) {

    return z * z % m;

}



loop_info get_loop() {

    vector<lint> appear_time(m, -1);

    lint now = x;

    lint time = 0;

    loop_info res;

    lint start_val;

    while (true) {

        if (appear_time[now] == -1) {

            appear_time[now] = time;

            time++;

            now = f(now);

        } else {

            res.loop_len = time - appear_time[now];

            res.prefix_len = appear_time[now];

            start_val = now;

            break;

        }

    }

    lint unit = 0;

    lint val = start_val;

    for (int i = 0; i < res.loop_len; i++) {

        unit += val;

        val = f(val);

    }

    res.unit = unit;

    return res;

}



lint simple_solve(lint k) {

    lint now = x;

    lint res = 0;

    for (int i = 0; i < k; i++) {

        res += now;

        now = f(now);

    }

    return res;

}



int main() {

    cin >> n >> x >> m;

    auto loop = get_loop();

    if (n < loop.prefix_len) {

        cout << simple_solve(n) << endl;

    } else {

        lint loop_num = (n - loop.prefix_len) / loop.loop_len;

        lint rem = n - loop_num * loop.loop_len;

        lint ans = simple_solve(rem) + loop.unit * loop_num;

        cout << ans << endl;

    }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef vector<vector<int>> Graph;

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};

#define pi 3.14159265359

#define inf 2147483647

#define INF 9223372036854775807

#define mod 1000000007

#define mod2 998244353



ll f(ll n, ll m) {

	return (n * n) % m;

}



int main() {

	ll N, X, M; cin >> N >> X >> M;

	ll A, preA, ans = 0;

	ll loopcnt = 0, cnt = 0, sum_loop = 0, rec_A;

	vector<int> visit(1000000);

	bool dub = false;

	for(int i = 1; i <= N; i++) {

		if(i == 1) {

			A = X;

			ans += A;

			visit[A] = 1;

			cnt++;

			continue;

		}

		preA = A;

		A = f(A, M);

		if(dub) {

			if(A == rec_A) break;

			ans += A; sum_loop += A; loopcnt++; cnt++;

		}

		else {

			if(visit[A]) {

				dub = true; rec_A = A; sum_loop += A; loopcnt++;

			}

			ans += A;

			cnt++;

			visit[A] = 1;

		}

	}

	A = preA;

	if(dub) {

		ans += sum_loop * ((N - cnt) / loopcnt);

		ll rem = (N - cnt) % loopcnt;

		for(int i = 0; i < rem; i++) {

			A = f(A, M);

			ans += A;

		}

	}

	cout << ans << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef vector<vector<int>> Graph;

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};

#define pi 3.14159265359

#define inf 2147483647

#define INF 9223372036854775807

#define mod 1000000007

#define mod2 998244353



ll f(ll n, ll m) {

	return (n * n) % m;

}



int main() {

	ll N, X, M; cin >> N >> X >> M;

	ll A, preA, ans = 0;

	ll loopcnt = 0, cnt = 0, sum_loop = 0, rec_A;

	vector<bool> visit(100001);

	bool dub = false;

	for(int i = 1; i <= N; i++) {

		if(i == 1) {

			A = X;

			ans += A;

			visit[A] = true;

			cnt++;

			continue;

		}

		preA = A;

		A = f(A, M);

		if(dub) {

			if(A == rec_A) break;

			ans += A; sum_loop += A; loopcnt++; cnt++;

		}

		else {

			if(visit[A]) {

				dub = true; rec_A = A; sum_loop += A; loopcnt++;

			}

			ans += A;

			cnt++;

			visit[A] = true;

		}

	}

	A = preA;

	if(dub) {

		ans += sum_loop * ((N - cnt) / loopcnt);

		ll rem = (N - cnt) % loopcnt;

		for(int i = 0; i < rem; i++) {

			A = f(A, M);

			ans += A;

		}

	}

	cout << ans << endl;

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define rep(i,n) for(i = 0;i < n;++i)

#define all(v) v.begin(), v.end()

using ll = long long;



int main()

{

    ll i,j;

    ll n,x,m;

    cin >> n >> x >> m;

    vector<vector<ll>> dub(m, vector<ll>(40, -1));

    vector<vector<ll>> dubsum(m, vector<ll>(40, 0));

    rep(i, m){

        dub[i][0] = i*i%m;

    }

    rep(i, 39){

        rep(j,m){

            dub[j][i + 1] = dub[dub[j][i]][i];

        }

    }

    rep(i,m){

        dubsum[i][0] = i;

    }

    rep(i,39){

        rep(j,m){

            dubsum[j][i+1] = dubsum[j][i] + dubsum[dub[j][i]][i];

        }

    }

    ll ans = 0;

    ll bit = 0;

    ll now = x;

    while(n){

        if(n & 1){

            ans += dubsum[now][bit];

            now = dub[now][bit];

        }

        ++bit;

        n >>= 1;

    }

    cout << ans << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define rep(i,n) for(i = 0;i < n;++i)

#define all(v) v.begin(), v.end()

using ll = long long;



int main()

{

    ll i,j;

    ll n,x,m;

    cin >> n >> x >> m;

    vector<ll> spare(m, -1);

    ll now = x;

    /**

    if(n <= 1e7){

        ll ans = 0;

        ll now = x;

        rep(i,n){

            ans += now;

            now = now*now%m;

        }

        cout << ans << endl;

        return 0;

    }**/

    rep(i,m){

        if(spare[now] != -1) break;

        else{

            spare[now] = i;

            now = now*now%m; 

        }

    }

    ll start = spare[now];

    ll end = i;

    ll shuuki = end-start;

    now = x;

    ll ans = 0;

    for(i = 0;i < start;++i){

        ans += now;

        now = now*now%m;

        --n;

        if(n == 0){

            cout << ans << endl;

            return 0;

        }

    }

    ll kurikaesi = 0;

    for(i = start;i < end;++i){

        kurikaesi += now;

        now = now*now % m;

    }

    ans += n/shuuki*kurikaesi;

    n %= shuuki;

    while(n){

        ans += now;

        now = now*now%m;

        --n;

    }

    cout << ans << endl;



    return 0;

}


// Fastest known solution for this problem: