fork download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<map>
  4. #include<algorithm>
  5. #include<string.h>
  6. using namespace std;
  7. int a[10000+100];
  8. int main()
  9. {
  10. int n,c,i,p,d,num;
  11. map<int,int> m;
  12. scanf("%d",&n);
  13. memset(a,0,sizeof(a));
  14. for(i=2;i<=n;i++)
  15. {
  16. if(a[i]==0)
  17. {
  18. p=2;c=0;num=i*p;
  19. while(num<=n)
  20. {
  21. a[num]=1;
  22. d=num;
  23. while(d%i==0)
  24. {
  25. d=d/i;
  26. c++;
  27. }
  28. p++;
  29. num=i*p;
  30. }
  31. m[i]=c+1;
  32. }
  33. }
  34. map<int,int>::iterator it;
  35. for(it=m.begin();it!=m.end();it++)
  36. {if(it!=m.begin())
  37. printf(" * ");
  38. printf("%d^%d",it->first,it->second);
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 2904KB
stdin
100
stdout
2^97 * 3^48 * 5^24 * 7^16 * 11^9 * 13^7 * 17^5 * 19^5 * 23^4 * 29^3 * 31^3 * 37^2 * 41^2 * 43^2 * 47^2 * 53^1 * 59^1 * 61^1 * 67^1 * 71^1 * 73^1 * 79^1 * 83^1 * 89^1 * 97^1