Advertisement
_rashed

UVA 10174

Jul 28th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(NULL);
  13.     cin.tie(0);
  14.     cout.tie(0);
  15.     //freopen("out.txt","w",stdout);
  16.     string in;
  17.     while(getline(cin,in)) {
  18.         bool mult = false;
  19.         //stringstream ss(in);
  20.         for(int i = 0; i < in.length(); i++) {
  21.             if(in[i] == ' ') {
  22.                 ll a = stoi(in.substr(0,i));
  23.                 ll b = stoi(in.substr(i+1));
  24.                 ll ans = 0;
  25.                 for(ll i = a; i <= b; i++) {
  26.                     //ans += ((i%2 == 1) ||(i%4 == 0));
  27.                     if((i%2 == 1) || (i%4 == 0)) {
  28.                         ans++;
  29.                     }
  30.                 }
  31.                 ans = b-a+1 - ans;
  32.                 cout << ans << "\n";
  33.                 mult = true;
  34.                 //cout << "a is " << a << " b is " << b << "\n";
  35.                 //cout << "diff is " << b-a+1 << "\n";
  36.             }
  37.         }
  38.         if(mult) {
  39.             continue;
  40.         }
  41.         ll n = stoi(in);
  42.         bool neg = false;
  43.         if(n == 0) {
  44.             cout << "0 0\n";
  45.             continue;
  46.         }
  47.         if(n < 0) {
  48.             neg = true;
  49.             n = abs(n);
  50.         }
  51.         if(n%2 == 1) {
  52.             ll a = (1+n)/2;
  53.             ll b = n-a;
  54.             if(neg) {
  55.                 swap(a,b);
  56.             }
  57.             cout << a << " " << b << "\n";
  58.         }
  59.         else if(n%4 == 0) {
  60.             ll a = (2 + (n/2))/2;
  61.             ll b = (n/2)-a;
  62.             if(neg) {
  63.                 swap(a,b);
  64.             }
  65.             cout << a << " " << b << "\n";
  66.         }
  67.         else {
  68.             cout << "Bachelor Number.\n";
  69.         }
  70.         //cout << "n is " << n << "\n";
  71.     }
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement