Advertisement
GerONSo

Untitled

Jan 24th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. int n;
  2. cin >> n;
  3. vector<int> a(n), b(n);
  4. for(int i = 0; i < n; i++) {
  5. cin >> a[i];
  6. }
  7. for(int i = 0; i < n; i++) {
  8. cin >> b[i];
  9. }
  10. int cur = 0;
  11.  
  12. for(int i = 0; i < n; i++) {
  13. for(int j = 0; j < n; j++) {
  14. if(__gcd(a[i], b[j]) + __gcd(a[j], b[i]) > __gcd(a[i], b[i]) + __gcd(a[j], b[j])) {
  15. swap(a[i], a[j]);
  16. }
  17. }
  18. }
  19. for(int i = 0; i < n; i++) {
  20. cur += __gcd(a[i], b[i]);
  21. }
  22. cout << cur;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement