fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. typedef long long ll;
  4. using namespace std;
  5. void Code_By_Mohamed_Khaled() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. cout.tie(nullptr);
  9. }
  10. ll Sum_of_range(ll l, ll r) {
  11. if (l > r) return 0;
  12. return r * (r + 1) / 2 - l * (l - 1) / 2;
  13. }
  14. ll mod=1e9+7;
  15. ll add(ll a, ll b) {return ((b % mod) + (a % mod)) % mod;}
  16. ll mul(ll a, ll b) {return ((b % mod) * (a % mod)) % mod;}
  17. int main() {
  18. Code_By_Mohamed_Khaled();
  19. // (A+B)%C=D if D>=C the no solution
  20. // i have two test cases A+B==D or A+B==D+C then get A from to equations and minimize answer
  21. // if A==0 A should be positive then A=C
  22. long long b,c,d;cin>>b>>c>>d;
  23. if (d>=c) {
  24. cout<<-1;
  25. return 0;
  26. }
  27. long long a=(d-b+c)%c;
  28. if (a==0)cout<<c;
  29. else cout<<a;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
-1