fork download
  1. ///==================================================///
  2. /// !! HELLO WORLD !! ///
  3. /// >>IT'S ME<< ///
  4. /// MOHAMMAD FAISAL ///
  5. ///==================================================///
  6. //THIS CODE IS IMPLEMENTED BY DUGGU_123(MOHAMMAD FAISAL)
  7. // author: MOHAMMAD FAISAL (email: mohammad.faisal78612@gmail.com)
  8. /*
  9.  
  10.   _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
  11.   _/ _/ _/ _/ _/ _/ _/ _/
  12.   _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
  13.   _/ _/ _/ _/ _/ _/ _/ _/
  14.   _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
  15.  
  16.  */
  17. #include<bits/stdc++.h>
  18. using namespace std ;
  19. #define ll long long
  20. #define ull unsigned long long int
  21. #define ld long double
  22. #define lop(i,n) for(int i=0;i<n;i++)
  23. #define rloop(i,n) for (int i = n-1; i >= 0; i--)
  24. #define loop(x, n) for(ll x = 0; x < n; ++ x)
  25. #define rep(x,n) for(ll x=1;x<=n;x++)
  26. #define mp make_pair
  27. #define pb push_back
  28. #define I cin>>
  29. #define O cout<<
  30. #define W(x) while(x--)
  31. #define si(x) scanf("%d",&x)
  32. #define pi(x) printf("%d\n",x)
  33. #define s(x) scanf("%lld",&x)
  34. #define p(x) printf("%lld\n",x)
  35. #define sc(x) scanf("%s",x)
  36. #define pc(x) printf("%s",x)
  37. #define pii pair<int,int>
  38. #define pll pair<ll,ll>
  39. #define F first
  40. #define S second
  41. #define inf 1e18
  42. #define MAX 10000000
  43. #define M 1000000007
  44. #define gcd(a,b) __gcd((a),(b))
  45. #define lcm(a,b) ((a)*(b))/gcd((a),(b))
  46. #define prec(x) fixed<<setprecision(15)<<x
  47. #define all(x) x.begin(),x.end()
  48. #define rall(x) x.rbegin(),x.rend()
  49. #define magic ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
  50. #define XXX return 0;
  51. #define br cout<<endl;
  52. const double PI=3.141592653589793238462643383279502884197169399375105820974944;
  53. //const ll inf = 1000000000;
  54. //const ll MOD = 1000000007;
  55. vector<bool> chkprime (MAX,true);
  56. unsigned primearray[5761459];
  57.  
  58.  
  59. void n_primes(){
  60. chkprime[0]=chkprime[1]=false;
  61. for(unsigned i=2;i*i<=MAX;i++){
  62. if(chkprime[i]){
  63. for(unsigned j=i;j*i<=MAX;j++) chkprime[i*j]=false;
  64. }
  65. }
  66. unsigned id = 1;
  67. primearray[0]=2;
  68.  
  69. for(int i=3;i<=MAX;i+=2){
  70. if(chkprime[i]){
  71. primearray[id++]=i;
  72. }
  73. }
  74. }
  75.  
  76. bool primity(long long n)
  77. {
  78. if(n<=1)
  79. return false;
  80. if(n<=3)
  81. return true;
  82.  
  83. if(n%2==0 || n%3==0)
  84. return false;
  85.  
  86. for(auto i=5; i*i<=n; i+=6)
  87. if(n%i==0 || n%(i+2)==0)
  88. return false;
  89.  
  90. return true;
  91. }
  92.  
  93. int power_x(int x, unsigned y)
  94. {
  95. if(y==0)
  96. return 1;
  97. if(!(y&1))
  98. return power_x(x,y>>1)*power_x(x,y>>1);
  99. return x*power_x(x,y>>1)*power_x(x,y>>1);
  100. }
  101.  
  102. int order_x(long long x)
  103. {
  104. int n=0;
  105. while(x)
  106. {
  107. n++;
  108. x/=10;
  109. }
  110. return n;
  111. }
  112. bool is_perfect_square(int n) {
  113. if (n < 0)
  114. return false;
  115. int root(round(sqrt(n)));
  116. return n == root * root;
  117. }
  118.  
  119. bool is_perfect_cube(int n) {
  120. int root(round(cbrt(n)));
  121. return n == root * root * root;
  122. }
  123.  
  124. /*bool isArm(long long n)
  125.  {
  126.  int pow=order_x(n);
  127.  long long temp=n,sum=0;
  128.  while(temp)
  129.  {
  130.  int r=temp%10;
  131.  sum+=power_x(r,pow);
  132.  temp/=10;
  133.  }
  134.  if(sum==n)
  135.  return true;
  136.  else
  137.  return false;
  138.  }*/
  139. bool isPrime(ll n)
  140. {
  141. if(n==2 || n==3)
  142. return true;
  143. if(n%2==0 || n%3==0)
  144. return false;
  145. ll div=6;
  146. while(div*div-2*div+1<=n)
  147. {
  148. if(n%(div-1)==0 || n%(div+1)==0)
  149. return false;
  150. div+=6;
  151. }
  152. return true;
  153. }
  154. int main ()
  155. {
  156. magic;
  157. /*
  158.  
  159.   O
  160.   <C>
  161.   /\
  162.  
  163.   */
  164. int t;
  165. I t;
  166. W(t)
  167. {
  168. ll n;
  169. I n;
  170. ll ans=INT_MAX;
  171. ll y;
  172. //int flag=0;
  173. if(isPrime(n))
  174. O n-1;
  175. else
  176. {
  177. for(ll i=1;i<=sqrt(n);i++)
  178. {
  179. if(n%i==0){
  180. y=n/i;
  181. ans=min(ans,abs(y-i));}}
  182. O ans;
  183. }
  184. br
  185. }
  186. XXX
  187. }
  188.  
Success #stdin #stdout 0s 37744KB
stdin
11
1989278372
12398324
123
121412
1999
11
1234
232
193
625
1024
stdout
21622499
3099577
38
224
1998
10
615
21
192
0
0