# HDU 4379 The More The Better [坑爹想法题]

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
inline int Rint() { int x; scanf("%d", &x); return x; }
inline int max(int x, int y) { return (x>y)? x: y; }
inline int min(int x, int y) { return (x<y)? x: y; }
#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(x) for(int i=0; i<(x); i++)
//typedef long long int64;
typedef __int64 int64;
#define INF (1<<30)
const double eps = 1e-8;
#define bug(s) cout<<#s<<"="<<s<<" "

int main()
{
int n, l, mod;
int A, b;
while(~scanf("%d%d%d%d%d", &n, &l, &A, &b, &mod))
{
int maxx = 0;
int minx = INF;
int havemin=0;

int cnt=0;
int mid = l/2;

for(int i=1; i<=n; i++)
{
int x = ((int64)A*i+b)%mod;
if(x<=mid)
{
cnt++;
maxx = max(maxx, x);
}
else
{
if(minx>x) minx=x, havemin=1;
}
}
if(havemin && maxx+minx <= l) cnt++;

printf("%d\n", cnt);
}
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客