Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define newl cout<<"\n";
- #define space cout<<" ";
- #define sz(x) x.size()
- #define NumOfDigit(w) log10(w) + 1
- #define MOD 1'000'000'007
- #define inf 2'000'000'000
- #define PI 3.141592654
- #define modulo(a, b, mod) ((((a) % (mod)) + ((b) % (mod))) % (mod))
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define fixed(n) fixed << setprecision(n)
- using namespace std;
- void zainab_hamdy(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll sum(ll n){
- return (n*(n+1))/2;
- }
- bool prime(ll n){
- if(n==2 || n==3) return true;
- if(n<2 || n%2==0 ) return false;
- for(int i=3;i<=sqrt(n);i+=2) if(n%i==0) return false;
- return true;
- }
- bool cmp(ll right,ll left){
- return left<right;
- }
- ll GCD(ll a,ll b){
- ll x=a,y=b,res;
- while(1){
- ll tmp=y;
- y=x%y;
- x=tmp;
- if(y==0){
- res=x;
- break;
- }
- }
- return res;
- }
- ll LCM(ll a,ll b){
- return (a/GCD(a,b))*b;
- }
- void Solve(){
- ll a,b,n; cin>>a>>b>>n;
- ll freq[10]{};
- for(int i=1;;i++){
- ll ans=(i*i*a)+(i*b);
- if(ans>n) break;
- if(ans<=n){
- while(ans){
- ll y=ans%10;
- freq[y]++;
- ans/=10;
- }
- }
- }
- ll mx=*max_element(freq,freq+10);
- for(int i=1;i<10;i++){
- if(freq[i]==mx && mx!=0){
- cout<<i;newl
- return;
- }
- }
- cout<<"-1\n";
- }
- int main(){
- zainab_hamdy();
- int t=1;
- cin>>t;
- while(t--)
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement