-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB. Fox Dividing Cheese - Codeforces Round 218 (Div. 2).cpp
More file actions
87 lines (69 loc) · 2.16 KB
/
B. Fox Dividing Cheese - Codeforces Round 218 (Div. 2).cpp
File metadata and controls
87 lines (69 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// std::ios_base::sync_with_stdio(false); // (removes the interoperability that happens between C's stdio.h and iostream )
// std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ); //(will neglect the c's stdio.h property of doing inline flushing with every line of code)
#include <iostream>
#include<numeric>
#include<vector>
#include<cmath>
#include<stack>
#include <iomanip>
#include <vector>
//#include<bits/stdc++.h>
#include <bitset>
//#include<iomanip>
#include <algorithm>
#include<queue>
//#include<deque>
//#include<numeric>
#include<set>
#include<unordered_set>
#include<map>
//#include<fstream>
//#include<sstream>
//#include <thread>
//#include <chrono>
#include<cstring>
#include<string>
#include <unordered_map>
#include<memory>
#include <iostream>
#include <thread>
//Solution is much simpler than that BTW.
std::unordered_map<int,int> firstNumberFactor;
std::unordered_map<int,int> secondNumberFactor;
std::vector<int> second;
int totalSize=0;
void getFactors(int theNumber ,std::unordered_map<int,int>* vec){
int temp = theNumber;
second.clear();
for(int i = 2 ; i <=temp ;i++){
//Condition for handling the big primes as it would go extremely deep till it stops.
if (i>5&&(((*vec)[2]+(*vec)[3]+(*vec)[5])==0)){
std::cout<<-1;
exit(0);
}
if (theNumber == 1 ){
totalSize+=second.size();
return;
}
while(theNumber%i == 0){
theNumber/=i;
(*vec)[i]++;
second.push_back(i);
}
}
}
int main(){
int a,b,exist=0;
std::cin>>a>>b;
getFactors(a,&firstNumberFactor);
getFactors(b,&secondNumberFactor);
for(int &element:second){
if(firstNumberFactor[element]){
secondNumberFactor[element]--;
firstNumberFactor[element]--;
exist+=2;
}
}
int toBeDeleted = firstNumberFactor[2]+firstNumberFactor[3]+firstNumberFactor[5]+secondNumberFactor[2]+secondNumberFactor[3]+secondNumberFactor[5];
(totalSize-exist-toBeDeleted>0)?std::cout<<-1:std::cout<<toBeDeleted;
}