fork download
  1. #include <bits/stdc++.h>
  2. #include <string.h>
  3. using namespace std;
  4. #define ll long long
  5.  
  6. void solve(){
  7. int n;cin>>n;
  8. if(n%3==0){cout<<0<<endl;return;}
  9. if(n%5==0){cout<<0<<endl;return;}
  10. int t=n/3;
  11. int i=0;int ans=100;
  12. while(i<=t){
  13. ans=min(ans,n-3*i-5*((n-3*i)/5));i++;
  14. }
  15. cout<<ans<<endl;
  16.  
  17. }
  18.  
  19. int main() {
  20. int t;
  21. cin>>t;
  22. while(t--)solve();
  23. return 0;
  24. }
Success #stdin #stdout 0s 5288KB
stdin
5
7
8
42
2
11
stdout
1
0
0
2
0