Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int n;
- cin >> n;
- vector<int> a(n), b(n);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i < n; i++) {
- cin >> b[i];
- }
- int cur = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- if(__gcd(a[i], b[j]) + __gcd(a[j], b[i]) > __gcd(a[i], b[i]) + __gcd(a[j], b[j])) {
- swap(a[i], a[j]);
- }
- }
- }
- for(int i = 0; i < n; i++) {
- cur += __gcd(a[i], b[i]);
- }
- cout << cur;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement