fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. class number_theory {
  6. public:
  7. ll gcd(ll x, ll y) {
  8. if (x == 0) return y;
  9. if (y == 0) return x;
  10. return gcd(y, x % y);
  11. }
  12. bool isprime(ll n) {
  13. if (n <= 1) return false;
  14. if (n <= 3) return true;
  15.  
  16. if (n % 2 == 0 || n % 3 == 0) return false;
  17.  
  18. for (ll i = 5; i * i <= n; i += 6)
  19. if (n % i == 0 || n % (i+2) == 0)
  20. return false;
  21.  
  22. return true;
  23. }
  24.  
  25. bool prime[15000105];
  26. void sieve(int n) {
  27. for (ll i = 0; i <= n; i++) prime[i] = 1;
  28. for (ll p = 2; p * p <= n; p++) {
  29. if (prime[p] == true) {
  30. for (ll i = p * p; i <= n; i += p)
  31. prime[i] = false;
  32. }
  33. }
  34. prime[1] = prime[0] = 0;
  35. }
  36.  
  37. vector<ll> primelist;
  38. bool __primes_generated__ = 0;
  39.  
  40. void genprimes(int n) {
  41. __primes_generated__ = 1;
  42. sieve(n + 1);
  43. for (ll i = 2; i <= n; i++) if (prime[i]) primelist.push_back(i);
  44. }
  45.  
  46. vector<ll> factorss(ll n) {
  47. if (!__primes_generated__) {
  48. cout << "Call genprimes you dope" << endl;
  49. exit(1);
  50. }
  51. vector<ll> facs;
  52.  
  53. for (ll i = 0; primelist[i] * primelist[i] <= n && i < primelist.size(); i++) {
  54. if (n % primelist[i] == 0) {
  55. while (n % primelist[i] == 0) {
  56. n /= primelist[i];
  57. facs.push_back(primelist[i]);
  58. }
  59. }
  60. }
  61. if (n > 1) {
  62. facs.push_back(n);
  63. }
  64. sort(facs.begin(), facs.end());
  65. return facs;
  66. }
  67. /*
  68. vector<ll> getdivs(ll n) {
  69.   vector<ll> divs;
  70.   for (ll i = 1; i * i <= n; i++) {
  71.   if (n % i == 0) {
  72.   divs.push_back(i);
  73.   divs.push_back(n / i);
  74.   }
  75.   }
  76.  
  77.   getunique(divs);
  78.   return divs;
  79.   }*/
  80. };
  81.  
  82. void solveMAXGCD(){
  83. int t, n;
  84. cin>>t;
  85. while(t--){
  86. cin>>n;
  87. if(n%2==0) cout<<n/2<<"\n";
  88. else cout<<(n-1)/2<<"\n";
  89. }
  90. }
  91.  
  92. void solveGCDLCM(){
  93. int t, n;
  94. cin>>t;
  95. while(t--){
  96. cin>>n;
  97. cout<<1<<" "<<n-1<<"\n";
  98. }
  99. }
  100. void solveCat(){
  101. int t; cin>>t;
  102. ll n,k;
  103. while(t--){
  104. cin>>n>>k;
  105. k--;
  106. if(n%2==0){
  107. cout<<1+(k%n)<<"\n";
  108. }
  109. else{
  110. ll inter=k/((n-1)/2);
  111. //no of spces it goes forward
  112. cout<<1+(k+inter)%n<<"\n";
  113. }
  114. }
  115. }
  116. void solveNew(){
  117. ll n;
  118. cin>>n;
  119. set<ll> ans;
  120. for(int i=1;i*i<=n;i++){
  121. if(n%i==0){
  122. ans.insert(((n/i)*(n/i-1)*i*0.5)+n/i);
  123. ans.insert(((n/i)*(i-1)*i*0.5)+(i));
  124. }
  125.  
  126. }
  127. for(auto it:ans) cout<<it<<" ";
  128. }
  129. void solveMath(){
  130. number_theory obj;
  131.  
  132. ll n; cin>>n;
  133. obj.genprimes(n);
  134. vector<ll> x=obj.factorss(n);
  135. map<ll,ll> cnt;
  136.  
  137. for (ll it:x) cnt[it]++;
  138. ll worst=0;
  139.  
  140. for(pair<ll,ll> x:cnt){
  141. worst=max(worst, x.second);
  142. }
  143.  
  144. ll b=0;
  145. while(1<<b < worst){
  146. b++;
  147. }
  148. ll ops=b;
  149. bool all_same=1;
  150. for(pair<ll,ll> x:cnt){
  151. if(x.second!=(1<<b)){
  152. all_same=0;
  153. break;
  154. }
  155. }
  156. //cout<<worst<<" ";
  157. if(!all_same) ++ops;
  158. ll p=1;
  159. for(pair<ll,ll> x:cnt ){
  160. p*=x.first;
  161. }
  162. cout<<p<<" "<<ops<<"\n";
  163. }
  164. void solveMeaningLess(){
  165. ll q; ll a; cin>>q;
  166. while(q--){
  167. cin>>a;
  168. ll msb=63-__builtin_clz(a);
  169. ll power_of_two_minus_one=(1<<(msb+1))-1;
  170. if(a!=power_of_two_minus_one){
  171. cout<<power_of_two_minus_one<<"\n";
  172. }
  173. else{
  174. ll best=1;
  175. for(int i=2;i*i<=a;i++){
  176. if(a%i==0){
  177. best=max(best,a/i);
  178. }
  179. }
  180. cout<<best<<"\n";
  181. // a xor b=b-a iff
  182. // gcd(a,b-a)=a if b is a factor of a
  183. }
  184. }
  185. }
  186. int main() {
  187. solveMeaningLess();
  188. return 0;
  189. }
Success #stdin #stdout 0s 5308KB
stdin
3
2
3
5
stdout
3
1
7