fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<math.h>
  4. #include<algorithm>
  5. #include<string>
  6. #include<string.h>
  7. #include<ctype.h>
  8.  
  9. #define mod 1000000007
  10. #define ll long long
  11. #define ull unsigned long long
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17. int temp,t,n,s[100005],count,a,b;
  18.  
  19. cin>>t;
  20.  
  21. while(t--)
  22. {
  23. count=0;
  24. cin>>n>>a>>b;
  25.  
  26. for(int i=0;i<n;i++)
  27. {
  28. cin>>s[i];
  29. if(s[i]%a==0 || s[i]%b==0)
  30. count++;
  31. else
  32. {
  33. if(s[i]<min(a,b))
  34. continue;
  35. temp=s[i];
  36. while(temp>0)
  37. {
  38. temp=temp-a;
  39. printf("temp=%d, b=%d, temp%%b=%d\n", temp, b, temp%b); // problem is here
  40. if(temp%b==0)
  41. {
  42. count++;
  43. break;
  44. }
  45.  
  46. }
  47. /*
  48.  
  49.   ** this part is redundant **
  50.   Solving once for whether ax + by = s[i] is enough
  51.  
  52.   if(temp%b==0)
  53.   continue;
  54.   temp=s[i];
  55.   while(temp>0)
  56.   {
  57.   temp=temp-b;
  58.   if(temp%a==0)
  59.   {
  60.   count++;
  61.   break;
  62.   }
  63.  
  64.   }
  65.   */
  66. }
  67. }
  68. cout<<count<<" "<<n-count<<endl;
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0s 3736KB
stdin
1
1 7 2
5
stdout
temp=-2, b=2, temp%b=0
1 0