###### 编程介的小学生

2017-11-12 02:55 阅读 770

# 反素数

10

Problem Description

Input

Output

Sample Input
3
2 3
1 10
47 359

Sample Output
2
6
240

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

#### 1条回答默认 最新

• will200811 2018-08-27 14:17

int process(int a,int b);
int eval(int);

int _tmain(int argc, _TCHAR* argv[])
{
char filename[]="test.txt";

``````getchar();
return 0;
``````

}

FILE* file;
char line[1024];
char data[1024];

``````int numline;
int i;
char *ptr;
int a[20];
int idx;
int j;
int val;

if((file=fopen(filename,"r"))!=NULL){
printf("ok");
fgets(line,1024,file);
numline = atoi(line);
printf("%d\n",numline);
for(i=1;i<=numline;i++){
fgets(data,1024,file);
ptr = strtok(data," ");
idx=0;
while(ptr!=NULL){
// printf("%8s,idx: %4d\n",ptr,idx);
a[idx++]=atoi(ptr);

ptr = strtok(NULL," ");
}
printf("idx: %d\n",idx);

for (j=0;j<idx;j++){
printf("array %d\n",a[j]);
}
val = process(a[0],a[1]);
printf("result %d\n",val);
}
fclose(file);
}
//  fclose(file);
``````

}

int process(int a,int b){
//int* p=(int*)malloc(sizeof(int)*(b-a+1));
int k;
int c;
int num=0;
int val=a;

``````for(k=a;k<=b;k++){
c = eval(k);
if(c>num){
val = k;
num = c;
}
}
return val;
``````

}

int eval(int n){
int i;
int c=0;
for(i=1;i<=n;i++){
if (n %i==0)
c++;
}
return c;
}

点赞 评论 复制链接分享