程式碼如下。
#include<stdio.h>
int prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
int len = 10;
int factors1[10];
int factors2[10];
void decompose(int* factors, int m, int n)
{
for (int i = 0; i < len; i++) factors[i] = 0;
for (int j = m; j <= n; j++)
int temp = j;
for (int t = 0; t < len; t++)
while (temp != 1 && temp % prime[t] == 0)
temp /= prime[t];
factors[t]++;
}
if (temp == 1) break;
程式碼如下。
#include<stdio.h>
int prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
int len = 10;
int factors1[10];
int factors2[10];
void decompose(int* factors, int m, int n)
{
for (int i = 0; i < len; i++) factors[i] = 0;
for (int j = m; j <= n; j++)
{
int temp = j;
for (int t = 0; t < len; t++)
{
while (temp != 1 && temp % prime[t] == 0)
{
temp /= prime[t];
factors[t]++;
}
if (temp == 1) break;
}
}
}