📄 plist.cpp
字号:
////////////////////////////////////////////////////////////////////////////////////////////////
// Plist.cpp //
// 作用:用于计算函数P表 //
// 编写者:王小龙(00512087) //
// 完成时间:2006、5、5 //
////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "stdafx.h"
#include "stdlib.h"
#include "math.h"
#include "time.h"
// 得到P表,返回a(PList 应该在主函数中建立)
//int *Plist =(int*)malloc(sizeof(int)*x_13);
int Get_PList(int *PList, int x_13)
{
int *List = (int*)malloc(sizeof (int)*x_13);
int i,j,a=0;
for (i=0 ; i<x_13 ; i++) // 赋值
{
List[i] = i+1;
}
int x_16 = (int)sqrt (x_13);
List[0]=0; // 单独考虑1
for(i=1; i<x_16; i++)
{
for(j=i+1; j<x_13 ; j++)
{
if (List[i]!=0 && List[j]!=0)
{
if(List[j] % List[i] ==0)
{
List[j] = 0;
}
}
}
}
int *p = PList;
for (i=0; i<x_13; i++)
{
if(List[i] != 0)
{
*p = List[i];
p++;
a++;
}
}
free(List);
return a; // 返回a值
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -