Statis

exista

Sep 8th, 2020
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. nr maxim:
  2. int nrmaxim (int n)
  3.  
  4. {
  5.  
  6. int m=n,max=n,nrc=1,c,f=1;
  7.  
  8. while (m>9) { ++nrc; m/=10; f*=10;}
  9.  
  10. for (int i=1;i<nrc;++i) {
  11.  
  12. c=n/f; n=n%f*10+c;
  13.  
  14. if (n>max) max=n;
  15.  
  16. }
  17.  
  18. return max;
  19.  
  20. }
  21. phi:
  22. int Phi(int n)
  23. {
  24. int r = n , d = 2;
  25. while(n > 1)
  26. {
  27. if(n % d == 0)
  28. {
  29. r = r / d * (d - 1);
  30. while(n % d == 0)
  31. n /= d;
  32. }
  33. d ++;
  34. if(d * d > n)
  35. d = n;
  36. }
  37. return r;
  38. }
  39. factorial2:
  40. int det(int n)
  41. {
  42. int p = 1 , k = 1;
  43. while(p < n) k ++ , p *= k;
  44. if(p == n) return p;
  45. int t = p / k;
  46. if(n - t <= p - n) return t;
  47. else return p;
  48. }
  49. numere norocoase:
  50. int norocoase(int a,int b)
  51. {
  52. int c=0,i;
  53. if (a%2==0)
  54. for (i=a+1;i<=b;i+=2)
  55. c++;
  56. else
  57. for (i=a;i<=b;i+=2)
  58. c++;
  59. return c;
  60. }
  61. zerofact:
  62. int nz (int n)
  63. {
  64. int k=0;
  65. for (int i=5; i<=n; i*=5)
  66. {
  67. k+=n/i;
  68. }
  69. return k;
  70. }
  71. poz:
  72. int poz(int x1, int y1, int l1, int i1, int x2, int y2, int l2, int i2)
  73.  
  74. {
  75.  
  76. int r;
  77.  
  78. if (x1==x2 && y1==y2 && l1==l2 && i1==i2) r=1;
  79.  
  80. else
  81.  
  82. {
  83.  
  84. if (x1+l1<x2 || y1+i1<y2 || x2+l2<x1 || y2+i2<y1 ) r=2;
  85.  
  86. else
  87.  
  88. {
  89.  
  90. if ((x1<x2 && y1<y2 && x1+l1>x2+l2 && y1+i1>y2+i2) || (x2<x1 && y2<y1 && x2+l2>x1+l1 && y2+i2>y1+i1)) r=0;
  91.  
  92. else
  93.  
  94. r=3;
  95.  
  96. }
  97.  
  98. }
  99.  
  100. return r;
  101.  
  102. }
  103. resturi1:
  104. #include <iostream>
  105.  
  106. using namespace std;
  107.  
  108. int resturi(int n, int x, int y, int r) {
  109.  
  110. int nr = 0, i;
  111. if (x > y) {
  112.  
  113. int temp = y;
  114.  
  115. y = x;
  116.  
  117. x = temp;
  118.  
  119. }
  120.  
  121. for (i = r; i <= n; i += y) {
  122.  
  123. if (i % x == r)
  124.  
  125. nr++;
  126.  
  127. }
  128.  
  129. return nr;
  130.  
  131. }
  132. diofantic:
  133. int diofantic(int n, int s[50001], int a,long long b,int c)
  134. {
  135. int k=0;int i=1; int j=n;
  136. while(i<=n && j>0)
  137. {
  138. if(a*s[i]*s[i]+b*s[j]*s[j]==c )
  139. {
  140. k++;
  141. i++;
  142. }
  143. if(a*s[i]*s[i]+b*s[j]*s[j]<c)
  144. i++;
  145. if(a*s[i]*s[i]+b*s[j]*s[j]>c)
  146. j--;
  147. }
  148. return k;
  149. }
  150. FRadical:
  151. void FRadical (int n, int &x, int &y)
  152. {
  153. x = 1;
  154. y = 1;
  155. int d = 2;
  156. while (n > 1) {
  157.  
  158. int e = 0;
  159. while (n % d == 0) {
  160.  
  161. e ++;
  162. n = n / d;
  163. }
  164. if (e) {
  165.  
  166. if (e % 2 == 0)
  167. x = x * pow(d, e / 2);
  168. else {
  169.  
  170. y = y * d;
  171. e --;
  172. if (e)
  173. x = x * pow (d, e / 2);
  174. }
  175. }
  176. d ++;
  177. }
  178.  
  179. }
  180. FInserare:
  181. int inserare (int &n) {
  182.  
  183. int x, v[15], k = 1;
  184. x = n;
  185. while (x)
  186. {
  187. v[k++] = x % 10;
  188. x = x / 10;
  189. }
  190. for (int i = k - 1; i >= 2; i--)
  191. {
  192. x = x * 10 + v[i];
  193. x = x * 10 + abs(v[i] - v[i-1]);
  194. }
  195. x = x * 10 + v[1];
  196. n = x;
  197. return n;
  198. }
  199. Impare_bac:
  200. void Impare (int &n) {
  201. int aux, uc, p = 1;
  202. aux = n;
  203. while (aux > 0) {
  204. uc = aux % 10;
  205. if (uc % 2 != 0)
  206. n -= p;
  207. p *= 10;
  208. aux /= 10; }
  209. }
  210. maxprime:
  211. int prim(int nr)
  212. {
  213. int prim=1;
  214. if(nr==0 || nr==1)
  215. prim=0;
  216. if(nr>2 && nr%2==0)
  217. prim=0;
  218. for(int d=3;d*d<=nr;d+=2)
  219. if(nr%d==0)
  220. prim=0;
  221. return prim;
  222. }
  223. void sub(int n,int &a,int &b)
  224. {
  225. bool stop=false,a1=false,b1=false;
  226. n--;
  227. while(n && stop==false)
  228. {
  229. if(prim(n))
  230. if(a1==false)
  231. a=n,a1=true;
  232. else
  233. b=n,b1=true;
  234. if(a1==true && b1==true)
  235. stop=1;
  236. n--;
  237. }
  238. }
  239. interval factorial:
  240. void interval(int n,int &a,int &b)
  241. {
  242. int f=1;
  243. for(int i=2;i<n;i++)
  244. f=f*i;
  245. a=f+1;
  246. b=f*n*(n+1)-1; }
Advertisement
Add Comment
Please, Sign In to add comment