Advertisement
Zeinab_Hamdy

Untitled

May 7th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define newl cout<<"\n";
  5. #define space cout<<" ";
  6. #define sz(x) x.size()
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define MOD 1'000'000'007
  9. #define inf 2'000'000'000
  10. #define PI 3.141592654
  11. #define modulo(a, b, mod) ((((a) % (mod)) + ((b) % (mod))) % (mod))
  12. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  13. #define all(v) v.begin(), v.end()
  14. #define rall(v) v.rbegin(), v.rend()
  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. using namespace std;  
  19. void zainab_hamdy(){
  20.   ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  21.   #ifndef ONLINE_JUDGE  
  22.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  23.   #endif
  24. }
  25. ll sum(ll n){
  26.   return (n*(n+1))/2;
  27. }
  28.  
  29. bool prime(ll n){
  30.   if(n==2 || n==3) return true;
  31.   if(n<2 || n%2==0  ) return false;
  32.   for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  33.   return true;
  34. }
  35. bool cmp(ll right,ll left){
  36.   return left<right;
  37. }
  38. ll GCD(ll a,ll b){
  39.  ll x=a,y=b,res;
  40.     while(1){
  41.            ll tmp=y;
  42.        y=x%y;
  43.        x=tmp;
  44.  if(y==0){
  45.   res=x;
  46.   break;
  47.     }
  48.  }
  49.     return res;
  50. }
  51.  ll LCM(ll a,ll b){
  52.     return (a/GCD(a,b))*b;
  53.  }
  54. void Solve(){
  55. ll a,b,n; cin>>a>>b>>n;
  56. ll freq[10]{};
  57. for(int i=1;;i++){
  58.   ll ans=(i*i*a)+(i*b);
  59.   if(ans>n) break;
  60.  if(ans<=n){
  61.    while(ans){
  62.      ll y=ans%10;
  63.      freq[y]++;
  64.      ans/=10;
  65.    }
  66.  }
  67. }
  68. ll mx=*max_element(freq,freq+10);
  69. for(int i=1;i<10;i++){
  70. if(freq[i]==mx && mx!=0){
  71.   cout<<i;newl
  72.   return;
  73. }
  74. }
  75. cout<<"-1\n";
  76. }
  77. int main(){
  78.   zainab_hamdy();
  79.   int t=1;
  80.  cin>>t;
  81.      while(t--)
  82.      Solve();
  83.  return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement