http://formatmysourcecode.blogspot.tw/
- 3月 29 週六 201418:08
format my source code to html
- 3月 29 週六 201418:05
relative prime (互質)
int hcf(int a , int h)
{
int temp;
while(1)
{
temp = a % h;
if(temp == 0)
{
return h;
}
a = h;
h = temp;
}
}
int relativePrimes(int* num , int n)
{
int count = 0;
for(int i = 0 ; i < n ; i++)
{
for(int j = i + 1 ; j < n ; j++)
{
int a = *(num + i);
int b = *(num + j);
int gcd = hcf(a , b);
if(gcd == 1)
{
count++;
}
}
}
return count;
}
{
int temp;
while(1)
{
temp = a % h;
if(temp == 0)
{
return h;
}
a = h;
h = temp;
}
}
int relativePrimes(int* num , int n)
{
int count = 0;
for(int i = 0 ; i < n ; i++)
{
for(int j = i + 1 ; j < n ; j++)
{
int a = *(num + i);
int b = *(num + j);
int gcd = hcf(a , b);
if(gcd == 1)
{
count++;
}
}
}
return count;
}
- 3月 29 週六 201418:04
gcd - greatest common divisor
int hcf(int a , int h)
{
int temp;
while(1)
{
temp = a % h;
if(temp == 0)
{
return h;
}
a = h;
h = temp;
}
}
{
int temp;
while(1)
{
temp = a % h;
if(temp == 0)
{
return h;
}
a = h;
h = temp;
}
}
- 3月 29 週六 201418:03
combination by pascal formula
int combination_pascal(int n , int r)
{
if(r == 0 || n == r)
{
return 1;
}
return combination_pascal(n - 1 , r) + combination_pascal(n - 1 , r - 1);
}
{
if(r == 0 || n == r)
{
return 1;
}
return combination_pascal(n - 1 , r) + combination_pascal(n - 1 , r - 1);
}
- 3月 29 週六 201418:02
combination
int factor(int n)
{
int ret = 1;
for(int i = 2 ; i <= n ; i++ )
{
ret = ret * i;
}
return ret;
}
int combination(int n , int r)
{
int ret = factor(n) / (factor(r) * factor(n-r));
return ret;
}
{
int ret = 1;
for(int i = 2 ; i <= n ; i++ )
{
ret = ret * i;
}
return ret;
}
int combination(int n , int r)
{
int ret = factor(n) / (factor(r) * factor(n-r));
return ret;
}
- 3月 29 週六 201418:01
scan n numbers into array
int* numArray(int n)
{
int* num = (int*)malloc(n * sizeof(int));
for(int i = 0 ; i < n ; i++)
{
scanf("%d\n" , num + i);
}
return num;
}
{
int* num = (int*)malloc(n * sizeof(int));
for(int i = 0 ; i < n ; i++)
{
scanf("%d\n" , num + i);
}
return num;
}
1
