fork download
  1. //Enter you code here.
  2. #include <stdio.h>
  3.  
  4. int main(void) {
  5. long int n;long long int a,b,c,d;int q;long long int i=2;int k=0;long long int z=0;
  6. scanf("%ld",&n);
  7. int x=0;
  8. while(x<n)
  9. {
  10. scanf("%d",&q);
  11. k=0;
  12. switch(q)
  13. {
  14. case 1:
  15. scanf("%lld %lld %lld",&a,&b,&c);
  16. while(k!=1)
  17. {
  18. d=a*z*z+b*z+c;
  19. i=2;
  20. if(d==0||d==1)
  21. {
  22. k=1;
  23. }
  24. else if(d==2||d==3)
  25. {
  26. k=0;
  27. }
  28. else
  29. {
  30. while(i<=d/2)
  31. {
  32. if(d%i==0)
  33. {
  34. k=1;
  35. break;
  36. }
  37. i++;
  38. }
  39. }
  40. if(k==1)
  41. {
  42. break;
  43. }
  44. z++;
  45. }
  46. if(k==1)
  47. {
  48. printf("%lld\n",z);
  49. }
  50. x++;
  51. break;
  52. case 2:
  53. scanf("%lld %lld",&a,&b);
  54. if(a==0 && b==0)
  55. {
  56. printf("0");
  57. }
  58. else
  59. {
  60. int u=1;int count1=0;int w=2;
  61. while (u<=b)
  62. {
  63. u+=w;
  64. count1++;
  65. w++;
  66. }
  67. u=1;int count2=0;w=2;
  68. while (u<a)
  69. {
  70. u+=w;
  71. count2++;
  72. w++;
  73. }
  74. int count=count1-count2;
  75. printf("%d\n",count);
  76. }
  77. x++;
  78. break;
  79. case 3:
  80. scanf("%lld %lld",&a,&b);
  81. int q=0;int count1=0;
  82. while(q<=b)
  83. {
  84. if(q%2==0 || q%3==0 || q%5==0)
  85. {
  86. count1++;
  87. }
  88. q++;
  89. }
  90. q=0;int count2=0;
  91. while(q<a)
  92. {
  93. if(q%2==0 || q%3==0 || q%5==0)
  94. {
  95. count2++;
  96. }
  97. q++;
  98. }
  99. int count = count1-count2;
  100. printf("%d\n",count);
  101. x++;
  102. break;
  103. case 4:
  104. scanf("%lld %lld",&a,&b);
  105. int f=a,h=a;int g;
  106. count=0;int max=0;
  107. while(h<=b)
  108. {
  109. f=h;count=0;
  110. while(f!=0)
  111. {
  112. g=f%2;
  113. f=((f-g)/2);
  114. if(g==1)
  115. {
  116. count++;
  117. }
  118. }
  119. if(count>max)
  120. {
  121. max=count;
  122. z=h;
  123. }
  124. h++;
  125. }
  126. f=b,h=b;
  127. count=0;long long int r=0;
  128. while(a<=h)
  129. {
  130. f=h;count=0;
  131. while(f!=0)
  132. {
  133. g=f%2;
  134. f=((f-g)/2);
  135. if(g==1)
  136. {
  137. count++;
  138. }
  139. }
  140. if(count<=max)
  141. {
  142. max=count;
  143. r=h;
  144. }
  145. h--;
  146. }
  147. printf("%lld %lld\n",r, z);
  148. x++;
  149. break;
  150. }
  151. }
  152. // Write your code here
  153. return 0;
  154. }
  155.  
  156. //Please indent properly.
  157.  
  158. <?php
  159. //program to find the common elements of the two array
  160. //here we have to array A and B from which w have to find the common element
  161. //first we sort then using merge sort and after then for traversing through
  162. //the array in one iteration we can find the comman elements the given array
  163. //this is an inspace algorithm meansno extra space is needed
  164.  
  165. //best case time complexity=O(nlogn)
  166. //O(nlogn)-> for sorting
  167. //O(n)-> for while loop to find comman element
  168.  
  169. //average case time complexity=O(nlogn)
  170. //O(nlogn)-> for sorting
  171. //O(n)-> for while loop to find comman element
  172.  
  173. //worst case time complexity =O(nlogn)
  174. //O(nlogn)-> for sorting
  175. //O(n)-> for while loop to find comman element
  176.  
  177.  
  178.  
  179. $commonArray=array();
  180. $A=array(3,4,5,6,7,8,9,10,36,58,27,48);
  181. $B=array(3,10,4,5,6,8,12,24,37,27,50);
  182. sort($A);
  183. sort($B);
  184. $size1=sizeof($A);
  185. $size2=sizeof($B);
  186. $counter1=0;
  187. $counter2=0;
  188. while(($counter1< $size1) && ($counter2)<($size2))//traversing through the array
  189. {
  190.  
  191. if ($A[$counter1] == $B[$counter2])
  192. {
  193. array_push($commonArray,$A[$counter1]); //to enter comman element in the output array
  194. $counter1=$counter1+1;
  195. $counter2=$counter2+1;
  196. }
  197. else if ($A[$counter1] < $B[$counter2])
  198. {
  199. $counter1=$counter1+1; }
  200.  
  201. else
  202. {
  203. $counter2=$counter2+1;
  204. }
  205. }
  206.  
  207. print_r($commonArray);//to print the output array
  208. ?>
  209.  
  210.  
Success #stdin #stdout 0.03s 25716KB
stdin
Standard input is empty
stdout
//Enter you code here.
#include <stdio.h>

int main(void) {
  long int n;long long int a,b,c,d;int q;long long int i=2;int k=0;long long int z=0;
  scanf("%ld",&n);
  int x=0;
  while(x<n)
  {
   scanf("%d",&q);
   k=0;
   switch(q)
     {
     case 1:
     scanf("%lld %lld %lld",&a,&b,&c);
    while(k!=1)
    {
       d=a*z*z+b*z+c;
       i=2;
      if(d==0||d==1)
      {
       k=1;
      }
      else if(d==2||d==3)
      {
        k=0;
      }
      else
      {
        while(i<=d/2)
         {
          if(d%i==0)
          {
            k=1;
            break;
          }
           i++;
         }
      }
      if(k==1)
      {
        break;
      }
      z++;
    }
       if(k==1)
       {
         printf("%lld\n",z);
       }
     x++;
     break;
     case 2:
     scanf("%lld %lld",&a,&b);
     if(a==0 && b==0)
     {
       printf("0");
     }
     else
     {
     int u=1;int count1=0;int w=2;
     while (u<=b)
       {
         u+=w;
         count1++;
         w++;
       }
       u=1;int count2=0;w=2;
     while (u<a)
       {
         u+=w;
         count2++;
         w++;
       }
     int count=count1-count2;
     printf("%d\n",count);
     }
     x++;
     break;
     case 3:
     scanf("%lld %lld",&a,&b);
     int q=0;int count1=0;
     while(q<=b)
       {
         if(q%2==0 || q%3==0 || q%5==0)
         {
           count1++;
         }
         q++;
       }
      q=0;int count2=0;
     while(q<a)
       {
         if(q%2==0 || q%3==0 || q%5==0)
         {
           count2++;
         }
         q++;
       }
     int count = count1-count2;
     printf("%d\n",count);
     x++;
     break;
     case 4:
     scanf("%lld %lld",&a,&b);
     int f=a,h=a;int g;
     count=0;int max=0;
     while(h<=b)
    {
      f=h;count=0;
      while(f!=0)
      {   
          g=f%2;
          f=((f-g)/2);
          if(g==1)
          {
           count++;
          }
      } 
      if(count>max)
      {
        max=count;
        z=h;
      }
     h++;
    }
     f=b,h=b;
     count=0;long long int r=0;
     while(a<=h)
    {
      f=h;count=0;
      while(f!=0)
      {   
          g=f%2;
          f=((f-g)/2);
          if(g==1)
          {
           count++;
          }
      } 
      if(count<=max)
      {
        max=count;
        r=h;
      }
     h--;
    }
     printf("%lld  %lld\n",r, z);
     x++;
     break;
     }
  }
  // Write your code here
  return 0;
}

//Please indent properly.

Array
(
    [0] => 3
    [1] => 4
    [2] => 5
    [3] => 6
    [4] => 8
    [5] => 10
    [6] => 27
)