1343A - Candies - CodeForces Solution


brute force math *900

Please click on ads to support us..

Python Code:

t=int(input())
for i in range(t):
    n=int(input())
    a=3
    i=2
    while True:
        if n%a==0:
            print(n//a)
            break
        else:
            a+=2**i
            i+=1

C++ Code:

// Author :- LAXMI KUMAR SAHANI

#include<bits/stdc++.h>
using namespace std;
#define precise(n) fixed<<setprecision(n)
#define loop(var,start,end) for(int var=start;var<end;var++)
#define input(x) for(auto &i:x) cin>>i;
#define print(x) for(auto i:x) cout<<i<<" ";cout<<"\n";
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define int long long
#define float long double
long double pi = acos(-1);


void solve() {
    int n;
    cin>>n;
    loop(i,2,33){
        int temp=pow(2,i);
        temp-=1;
        if(n%temp==0){
            cout<<(n/temp)<<"\n";
            return;
        }
    }
}
int32_t main() {

    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses