Source code for submission s745

mosquito.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7. int a[3];
  8. int b[3];
  9. int N;
  10.  
  11. while(scanf("%i %i %i %i %i %i %i",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2], &N)==7)
  12. {
  13. int z = N % 3;
  14.  
  15. int x = a[z];
  16.  
  17. int y2 = b[1] * b[2];
  18.  
  19. int y1 = b[0];
  20.  
  21. for (int i = z; i>=1; i--)
  22. {
  23. x = x / b[i];
  24. }
  25.  
  26. int d;
  27.  
  28. if ((y1 != 0) && (N >= 3))
  29. {
  30.  
  31. if (y1 > y2)
  32. {
  33. d = y1 / y2;
  34. if (d != 1)
  35. x = x * (d * (N / 3));
  36. }
  37. if (y1 < y2)
  38. {
  39. d = y2 / y1;
  40. if (d != 1)
  41. x = x / (d * (N / 3));
  42. }
  43. }
  44.  
  45. else
  46. {
  47. if ( N >= 3)
  48. x = 0;
  49. }
  50.  
  51. printf("%i\n",x);
  52.  
  53.  
  54. }
  55. return 0;
  56. }