Untitled
user_5668965
c_cpp
10 days ago
970 B
1
Indexable
Never
#include <bits/stdc++.h> using namespace std; #define endl "\n" typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld; void solve() { int a, b; cin >> a >> b; int n2a = 0, n3a = 0, n5a = 0; int n2b = 0, n3b = 0, n5b = 0; while (a % 2 == 0) { a /= 2; n2a++; } while (a % 3 == 0) { a /= 3; n3a++; } while (a % 5 == 0) { a /= 5; n5a++; } while (b % 2 == 0) { b /= 2; n2b++; } while (b % 3 == 0) { b /= 3; n3b++; } while (b % 5 == 0) { b /= 5; n5b++; } if (a != b) cout << -1; else cout << abs(n2a - n2b) + abs(n3a - n3b) + abs(n5a - n5b); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
Leave a Comment