Pagini recente » Cod sursa (job #3285665) | Cod sursa (job #1194909) | Cod sursa (job #1231254) | Cod sursa (job #8233) | Cod sursa (job #3191339)
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
using ll=long long;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int Nmax=1e6+5;
int c[Nmax];
vector<pair<int,int>> ev[Nmax];
set<int> s;
int main()
{
ll n,a,b;
fin>>n;
fin>>a>>b>>c[1];
ev[min(a,b)].push_back({1,0});
ev[max(a,b)+1].push_back({1,1});
for(ll i=2;i<=n-1;i++)
{
a=(a*i)%n;
b=(b*i)%n;
c[i]=(c[i-1]*i)%n;
ev[min(a,b)].push_back({i,0});
ev[max(a,b)+1].push_back({i,1});
}
for(ll i=1;i<n;i++)
{
sort(ev[i].begin(),ev[i].end());
for(int j=0;j<ev[i].size();j++)
{
if(ev[i][j].second==0)
{
s.insert(ev[i][j].first);
}
else s.erase(ev[i][j].first);
}
if(s.empty()) fout<<0<<'\n';
else fout<<c[*(s.rbegin())]<<'\n';
}
return 0;
}