fork(7) download
  1. #include <iostream>
  2.  
  3. #include <math.h>
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12.  
  13. {
  14.  
  15. float c;
  16.  
  17.  
  18.  
  19. while(cin>>c){
  20.  
  21. int i;
  22.  
  23. int c1=(int)c;
  24.  
  25. int Count=sqrt(c);
  26.  
  27.  
  28.  
  29. if(c1==1)
  30.  
  31. {
  32.  
  33. cout<<"非質數"<<endl;
  34.  
  35. continue;
  36.  
  37. }
  38.  
  39. if(c1==2)
  40.  
  41. {
  42.  
  43. cout<<"質數"<<endl;
  44.  
  45. continue;
  46.  
  47. }
  48.  
  49. for(i=2;i<Count+1;i++)
  50.  
  51. {
  52.  
  53. if(c1%i==0)
  54.  
  55. {
  56.  
  57. cout<<"非質數"<<endl;
  58.  
  59. break;
  60.  
  61. }
  62.  
  63. }
  64.  
  65. if(i==Count+1)
  66.  
  67. {
  68.  
  69. cout<<"質數"<<endl;
  70.  
  71. }
  72.  
  73. }
  74.  
  75.  
  76.  
  77. return 0;
  78.  
  79. }
  80.  
  81.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Standard output is empty