fork(1) download
  1. //make a program to take an array and tell all sum of number of prime factors of it..
  2. //so make a seive array of the least prime factor of all numbers
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define n 1000000
  6. int main(){
  7.  
  8. vector<int> leasp(n,0);
  9. leasp[0]=0;
  10. leasp[1]=0;
  11. for(int i=2;i*i<n;i++)
  12. {
  13. if(leasp[i]==0){//the inner loop would run only for primes
  14. for(int j=i*i;j<n;j+=i)
  15. {
  16. if(leasp[j]==0){
  17. leasp[j]=i;
  18. }
  19. }
  20. }
  21. }
  22. //then for all of the primes we have to put that value to it
  23. for(int i=2;i<n;i++)
  24. {
  25. if(leasp[i]==0)
  26. {
  27. leasp[i]=i;
  28. }
  29. }
  30. for(int i=0;i<50;i++)
  31. {
  32.  
  33. cout<<leasp[i]<< " ";
  34. }
  35. }
  36.  
Success #stdin #stdout 0.01s 6912KB
stdin
Standard input is empty
stdout
0 0 2 3 2 5 2 7 2 3 2 11 2 13 2 3 2 17 2 19 2 3 2 23 2 5 2 3 2 29 2 31 2 3 2 5 2 37 2 3 2 41 2 43 2 3 2 47 2 7