fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool func(int x, int b){
  5. int num=0;
  6. while(x>0){
  7. num=x%10;
  8. if(num==b)
  9. return true;
  10. x/=10;
  11. }
  12. return false;
  13. }
  14. int main(){
  15. int S, E, B, K;
  16. cin>>S>>E>>B>>K;
  17. int ans=-1, cnt=0;
  18. for(int i=S; i<=E; i++){
  19. if(i%B==0 or func(i,B)){
  20. cnt++;
  21. //cout<<cnt<<':'<<i<<'\n';
  22. }
  23. if(cnt==K){
  24. ans=i;
  25. break;
  26. }
  27. }
  28. cout<<ans;
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5528KB
stdin
Standard input is empty
stdout
-1