Created
October 12, 2016 07:25
-
-
Save ititorit/60c0f22b4179c9fbc03f39c446b20b9d to your computer and use it in GitHub Desktop.
Meeting Rooms ACM/ICPC 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Link Contest: https://drive.google.com/file/d/0BwNqLoGeu3p0ajFCMjZFRW1rVjA/view?pli=1 | |
// Author : Nguyen Minh Tuan | |
// lang : C/C++ | |
#include <algorithm> | |
#include <functional> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
#include <set> | |
#include <map> | |
#include <cmath> | |
#define _for(i,a,b) for(int i=(a),_b_=(b),_d_=(a<b?1:-1);i!=_b_;i+=_d_) | |
#define FOR(i,a,b) for(int i = a; i <= b; i++) | |
#define _it(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i) | |
#define _all(v) v.begin(), v.end() | |
#define DEBUG(x) { cout << #x << " = " << x << endl; } | |
#define sqr(x) ((x)*(x)) | |
using namespace std; | |
typedef long long ll; | |
typedef unsigned long long ull; | |
inline ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; } | |
ull lcm2(ull a, ull b) { | |
return (a*b)/gcd(a,b); | |
} | |
ull lcm(int a, int b, int c, int d) { | |
return lcm2(lcm2(a,b),lcm2(c,d)); | |
} | |
int main(){ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
// solution starts... | |
#ifndef ONLINE_JUDGE | |
freopen("INPUT.inp", "r", stdin); | |
#endif | |
int m, n, s, t, p; | |
cin >> m >> n >> s >> t >> p; | |
ull ans; | |
FOR(v,1,p) { | |
if((v*lcm(m,n,s,t) + 1) % p == 0) { | |
ans = (v*lcm(m,n,s,t) + 1); | |
break; | |
} | |
} | |
cout << ans << '\n'; | |
// solution ends... | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment