Advertisement
Saleh127

UVA 11415

Oct 31st, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. ll f[10001000];
  6.  
  7. ll factor(ll n)
  8. {
  9. ll c=0;
  10. while(n%2==0)
  11. {
  12. c++;
  13. n/=2;
  14. }
  15. for(ll i=3; i<=sqrt(n); i+=2)
  16. {
  17. if(n%i==0)
  18. {
  19. while(n%i==0)
  20. {
  21. c++;
  22. n/=i;
  23. }
  24. }
  25. }
  26. if(n>1) c++;
  27.  
  28. return c;
  29. }
  30.  
  31. void precal()
  32. {
  33. f[0]=1;
  34. f[1]=1;
  35. f[2]=1;
  36. f[3]=2;
  37. for(ll i=4; i<=2703670; i++)
  38. {
  39. f[i]=f[i-1]+factor(i);
  40. }
  41. }
  42.  
  43. ll searchh(ll x)
  44. {
  45. ll lo=0,hi=2703670,mid,ans=-1;
  46. while(lo<=hi)
  47. {
  48. mid=(lo+hi)/2;
  49. if(f[mid]<=x)
  50. {
  51. lo=mid+1;
  52. ans=lo;
  53. }
  54. else hi=mid-1;
  55. }
  56. return ans;
  57. }
  58.  
  59. int main()
  60. {
  61. ios_base::sync_with_stdio(0);
  62. cin.tie(0);
  63. cout.tie(0);
  64.  
  65. precal();
  66.  
  67. ll n;
  68.  
  69. test
  70. {
  71.  
  72. cin>>n;
  73.  
  74. cout<<searchh(n)<<endl;
  75.  
  76. }
  77.  
  78.  
  79. return 0;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement