Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #define dokle 1234567
  4.  
  5. using namespace std;
  6.  
  7. char buff[dokle], *pozicija=buff+dokle;
  8. inline char ucitaj_sledeci()
  9. {
  10. if(pozicija==buff+dokle)
  11. {
  12. fread(buff,1,dokle,stdin);
  13. pozicija=buff;
  14. }
  15. return *pozicija++;
  16. }
  17. inline void ispisi_char(char c)
  18. {
  19. fwrite(&c,1,sizeof(c),stdout);
  20. }
  21. inline int ucitaj_int()
  22. {
  23. int broj=0;
  24. char c;
  25. while((c=ucitaj_sledeci())<'0' || c>'9');
  26. do
  27. {
  28. broj=broj*10+(c-'0');
  29. }while((c=ucitaj_sledeci())>='0' && c<='9');
  30. return broj;
  31. }
  32. inline char ucitaj_char()
  33. {
  34. char c;
  35. while( (c=ucitaj_sledeci())<'a' || c>'z' )
  36. return c;
  37. }
  38. inline void ispisi_int(int n)
  39. {
  40. int cifre[10],brcifre;
  41. if(n==0)
  42. {
  43. ispisi_char('0');
  44. ispisi_char('\n');
  45. return;
  46. }
  47. for(brcifre=0; n; brcifre++)
  48. {
  49. cifre[brcifre]=n%10;
  50. n/=10;
  51. }
  52. for(;brcifre;brcifre--) ispisi_char(cifre[brcifre-1]+'0');
  53. ispisi_char('\n');
  54. }
  55.  
  56.  
  57.  
  58. // ZADATAK:
  59. bool composite[200000] ;
  60. int izlozilac[200000] , flag;
  61. int n, x ;
  62.  
  63. void eratosten();
  64.  
  65.  
  66.  
  67.  
  68. int main ()
  69. {
  70.  
  71. eratosten();
  72.  
  73. n=ucitaj_int();
  74.  
  75. for( int l=0; l<n; ++l ) {
  76.  
  77.  
  78. scanf("%d", &x);
  79.  
  80. if( composite[x] == false ) { printf("%d^1\n", x ); continue; }
  81.  
  82.  
  83. for( int i=2; i<200000 && x!=1; ++i ) {
  84.  
  85. if( !composite[i] && x%i == 0 ){
  86.  
  87. if( i>x ) { break; }
  88.  
  89. while( x%i == 0 ) { izlozilac[i]++; x/=i; }
  90. }
  91.  
  92. if( izlozilac[i]>0 && !flag ) { printf("%d^%d", i, izlozilac[i]); flag= true; izlozilac[i]=0; }
  93. else if( izlozilac[i]>0 && flag){ printf("*%d^%d", i, izlozilac[i]); izlozilac[i]=0; }
  94. if( composite[x] == false && x!=1 ){ cout<<"*"<<x<<"^1"; break; }
  95. }
  96. flag=0;
  97. printf("\n");
  98.  
  99. }
  100.  
  101. return 0;
  102. }
  103.  
  104. void eratosten()
  105. {
  106.  
  107. for (int i = 2; i <= 448; i++)
  108. {
  109.  
  110. if (!composite[i])
  111. {
  112.  
  113. for (int j = i; i * j <= 200000; j++)
  114. {
  115. if (composite[i * j] == 0)
  116. {
  117. composite[i * j] = true;
  118. }
  119. }
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement