Created
November 16, 2018 16:42
-
-
Save tabvn/3f835551712bd4922b014cc141da64cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
long long jump(long long a, long long b, long long k){ | |
if(k == 1){ | |
return a; | |
} | |
if(k == 2){ | |
return a - b; | |
} | |
long long stepForward; | |
long long value = 0; | |
if(k %2 == 0){ | |
// so chan | |
stepForward = k/2; | |
}else{ | |
// so le | |
stepForward = k/2 +1; | |
} | |
return a * stepForward - (k - stepForward) * b; | |
} | |
int main(){ | |
int t; | |
long long a,b,k; | |
cin >> t; | |
for (int i = 0; i < t; ++i){ | |
cin >> a >> b >> k; | |
cout << jump(a, b, k) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment