Advertisement
LA77

Untitled

Sep 24th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /* file: smoking.c */
  2. /* author: Anastase Luca-George (email: l.anastase@student.rug.nl) */
  3. /* date: 9/17/2024 */
  4. /* version: 1.0 */
  5. /* Description: This program tells us what number is divisible with 1, 2, ... n, and be as small as possible, n being an input.
  6.  
  7. */
  8.  
  9. #include <stdio.h>
  10.  
  11. int main(int argc, char *argv[]) {
  12. int n, val = 1;
  13. scanf("%d", &n);
  14.  
  15. for(int i = 2; i <= n; ++ i) { // Iterating through every number till n
  16. if(val % i != 0) {
  17. for(int d = 2; d <= i; ++ d) { // Iteraing through every divisor of n. We see how much we should add to val for it to have the needed number of divisors
  18. int cpy1 = i, cpy2 = val;
  19. int cnt1 = 0, cnt2 = 0;
  20. while(cpy1 % d == 0) { // getting how many times d appears as a divisor in i
  21. cnt1++;
  22. cpy1/=d;
  23. }
  24. while(cpy2 % d == 0) { // getting how many times d appears as a divisor in val
  25. cnt2++;
  26. cpy2/=d;
  27. }
  28. if(cnt1 > cnt2) { \
  29. int c = cnt1 - cnt2;
  30. val*= (c * d);
  31. }
  32. }
  33. }
  34. }
  35.  
  36. printf("%d\n", val);
  37. return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement