Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
42
Task/Proper-divisors/C/proper-divisors-1.c
Normal file
42
Task/Proper-divisors/C/proper-divisors-1.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int proper_divisors(const int n, bool print_flag)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (n % i == 0) {
|
||||
count++;
|
||||
if (print_flag)
|
||||
printf("%d ", i);
|
||||
}
|
||||
}
|
||||
|
||||
if (print_flag)
|
||||
printf("\n");
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for (int i = 1; i <= 10; ++i) {
|
||||
printf("%d: ", i);
|
||||
proper_divisors(i, true);
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
int max_i = 1;
|
||||
|
||||
for (int i = 1; i <= 20000; ++i) {
|
||||
int v = proper_divisors(i, false);
|
||||
if (v >= max) {
|
||||
max = v;
|
||||
max_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d with %d divisors\n", max_i, max);
|
||||
return 0;
|
||||
}
|
||||
69
Task/Proper-divisors/C/proper-divisors-2.c
Normal file
69
Task/Proper-divisors/C/proper-divisors-2.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int proper_divisors(const int n, bool print_flag)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (n % i == 0) {
|
||||
count++;
|
||||
if (print_flag)
|
||||
printf("%d ", i);
|
||||
}
|
||||
}
|
||||
|
||||
if (print_flag)
|
||||
printf("\n");
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int countProperDivisors(int n){
|
||||
int prod = 1,i,count=0;
|
||||
|
||||
while(n%2==0){
|
||||
count++;
|
||||
n /= 2;
|
||||
}
|
||||
|
||||
prod *= (1+count);
|
||||
|
||||
for(i=3;i*i<=n;i+=2){
|
||||
count = 0;
|
||||
|
||||
while(n%i==0){
|
||||
count++;
|
||||
n /= i;
|
||||
}
|
||||
|
||||
prod *= (1+count);
|
||||
}
|
||||
|
||||
if(n>2)
|
||||
prod *= 2;
|
||||
|
||||
return prod - 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for (int i = 1; i <= 10; ++i) {
|
||||
printf("%d: ", i);
|
||||
proper_divisors(i, true);
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
int max_i = 1;
|
||||
|
||||
for (int i = 1; i <= 20000; ++i) {
|
||||
int v = countProperDivisors(i);
|
||||
if (v >= max) {
|
||||
max = v;
|
||||
max_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d with %d divisors\n", max_i, max);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue