Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define pb push_back
- int main(){
- int a, b, c, d, f, i;
- map <int, int> used1, used2;
- cin >> a >> b >> c >> d >> f;
- int tmpa = a, tmpc = c;
- for(i = 2; i*i <= tmpa; i++){
- while(tmpa%i == 0){
- tmpa /= i;
- used1[i] += b;
- }
- }
- if(tmpa > 1){
- used1[tmpa] += b;
- }
- for(i = 2; i*i <= tmpc; i++){
- while(tmpc%i == 0){
- tmpc /= i;
- used2[i] += d;
- }
- }
- if(tmpc > 1){
- used2[tmpc] += d;
- }
- vector <int> v;
- set <int> st;
- tmpa = a;
- for(i = 2; i*i <= tmpa; i++){
- while(tmpa%i == 0){
- tmpa /= i;
- st.insert(i);
- }
- }
- if(tmpa > 1){
- st.insert(tmpa);
- }
- for(set <int> :: iterator it = st.begin(); it != st.end(); it++){
- int to = *it;
- for(i = 0; i < min(used1[to], used2[to]); i++){
- v.pb(to);
- }
- }
- int res = 1;
- for(i = 0; i < v.size(); i++){
- int to = v[i];
- res *= to;
- res %= f;
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement