fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const ll N=1e7+2;
  5. map<ll,vector<ll> > g;
  6. ll a[N],n,m;
  7. void ok(){
  8.  
  9. for(int i=1;i<=N;i++)
  10. a[i]=i;
  11.  
  12. for(int i=2;i<=N;i++)
  13. if(a[i]==i){
  14. for(int j=2*i;j<=N;j+=i)
  15. if(a[j]==j)
  16. a[j]=i;
  17. }
  18. }
  19.  
  20. void siu(ll n){
  21. ll x=n;
  22. ll d=1;
  23. ll d1[n+2]={};
  24. vector<ll> v;
  25. while(x!=1){
  26. if(d1[a[x]]==0){
  27. v.push_back(a[x]);
  28. }
  29. d1[a[x]]++;
  30. x/=a[x];
  31. }
  32. for(auto x:v)
  33. if( (d1[x]%2) )
  34. d*=x;
  35.  
  36. g[d].push_back(n);
  37. }
  38. int main()
  39. {
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42. ok();
  43. ll n,m;
  44. cin>>n>>m;
  45. for(int i=1;i<=n;i++)
  46. siu(i);
  47. for(auto x:g[6])
  48. cout<<x<<" ";
  49. return 0;
  50. }
  51.  
  52.  
Success #stdin #stdout 2.28s 89384KB
stdin
100000 10
stdout
6 24 54 96 150 216 294 384 486 600 726 864 1014 1176 1350 1536 1734 1944 2166 2400 2646 2904 3174 3456 3750 4056 4374 4704 5046 5400 5766 6144 6534 6936 7350 7776 8214 8664 9126 9600 10086 10584 11094 11616 12150 12696 13254 13824 14406 15000 15606 16224 16854 17496 18150 18816 19494 20184 20886 21600 22326 23064 23814 24576 25350 26136 26934 27744 28566 29400 30246 31104 31974 32856 33750 34656 35574 36504 37446 38400 39366 40344 41334 42336 43350 44376 45414 46464 47526 48600 49686 50784 51894 53016 54150 55296 56454 57624 58806 60000 61206 62424 63654 64896 66150 67416 68694 69984 71286 72600 73926 75264 76614 77976 79350 80736 82134 83544 84966 86400 87846 89304 90774 92256 93750 95256 96774 98304 99846