Advertisement
Zeinab_Hamdy

Untitled

Sep 18th, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define nl cout<<"\n";
  5. #define sp cout<<" ";
  6. #define sz(x) x.size()
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. #define MOD (ll) 1e9 + 7;
  19. using namespace std;
  20.  
  21. void zainab_hamdy(){
  22.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  23.     //freopen("filename.in" , "r" ,stdin);
  24. #ifndef ONLINE_JUDGE
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28. /*bool prime(ll n){
  29.     if(n==2 || n==3) return true;
  30.     if(n<2 || n%2==0  ) return false;
  31.     for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  32.     return true;
  33. }*/
  34.  
  35.  
  36. void isAccepted(){
  37.  
  38. ll n ,q ; cin >> q >>  n ;
  39.  
  40. vector <ll > ans ;
  41. for(ll i=pow(2,n-1)+1 ; i<=pow(10,n)-1 ; i++){
  42.     string t, s =to_string(i);
  43.     t=s;
  44.     reverse(all(s));
  45.     if(s==t and sz(s)==n)
  46.         ans.push_back(i);
  47.         if(sz(s) > n ) break;
  48.        
  49. }
  50. //cout (ans);
  51. int tmp;
  52. while(q--){
  53.     cin >> tmp;
  54.     if (tmp>sz(ans)) cout <<"-1\n";
  55.     else cout << ans[tmp-1] <<"\n";
  56. }
  57. }
  58. int main(){
  59.                 zainab_hamdy();
  60.            
  61.     int testCase=1;  // one test case
  62.    // cin >> testCase;
  63.     while(testCase--)
  64.         isAccepted();  // my code
  65.        
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement