Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* file: smoking.c */
- /* author: Anastase Luca-George (email: l.anastase@student.rug.nl) */
- /* date: 9/17/2024 */
- /* version: 1.0 */
- /* Description: This program tells us what number is divisible with 1, 2, ... n, and be as small as possible, n being an input.
- */
- #include <stdio.h>
- int main(int argc, char *argv[]) {
- int n, val = 1;
- scanf("%d", &n);
- for(int i = 2; i <= n; ++ i) { // Iterating through every number till n
- if(val % i != 0) {
- 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
- int cpy1 = i, cpy2 = val;
- int cnt1 = 0, cnt2 = 0;
- while(cpy1 % d == 0) { // getting how many times d appears as a divisor in i
- cnt1++;
- cpy1/=d;
- }
- while(cpy2 % d == 0) { // getting how many times d appears as a divisor in val
- cnt2++;
- cpy2/=d;
- }
- if(cnt1 > cnt2) { \
- int c = cnt1 - cnt2;
- val*= (c * d);
- }
- }
- }
- }
- printf("%d\n", val);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement