fork download
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int N, cnt = 0, cnt1 = 0;
  9. cin >> N;
  10. if (N % 5 == 0)
  11. {
  12. cnt1 = N / 5;
  13. }
  14. else if (N % 3 == 0)
  15. {
  16. cnt1 = N / 3;
  17. }
  18.  
  19. for (size_t i = 1; i <= N/5; i++)
  20. {
  21. for (size_t j = 1; j <= N/3; j++)
  22. {
  23. if (5 * i + 3 * j == N)
  24. {
  25. cnt += i + j;
  26. }
  27. }
  28. }
  29. if (cnt > 0 and cnt1 > 0)
  30. {
  31. cout << min(cnt, cnt1);
  32. }
  33. else if (cnt == 0 and cnt1 > 0)
  34. {
  35. cout << cnt1;
  36. }
  37. else if (cnt1 == 0 and cnt > 0)
  38. {
  39. cout << cnt;
  40. }
  41. else
  42. {
  43. cout << -1;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5308KB
stdin
3003
stdout
1001