Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:到底每次做完之后q应在哪个地方清0呀????????

Posted by 90405130 at 2004-12-30 10:39:01 on Problem 1218
In Reply To:到底每次做完之后q应在哪个地方清0呀???????? Posted by:00430030 at 2004-12-30 10:24:52
#include<stdio.h>
#include<malloc.h>
void main(){
	int m,n,i,j,k;
         int *per;
	scanf("%d",&m);
	for(k=0;k<m;k++){
		scanf("%d",&n);
		per=(int*)malloc((n+1)*sizeof(int));
		for(i=1;i<=n;i++){
			per[i]=0;
		}
		for(i=1;i<=n;i++){
			for(j=i;j<=n;j+=i){
				if(per[j]==0) per[j]=1;
				else per[j]=0;
			}
		}
                  j=0;
		for(i=1;i<=n;i++){
			if(per[i]==1) j++;
		}
		printf("%d\n",j);
		free(per);
	}
}

       


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator