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

萌新不会那么简单的算法,附上类似开灯的垃圾代码

Posted by XianYugong at 2017-03-18 18:26:37 on Problem 1218
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXN 105
int sign[MAXN];
int main()
{
	int count, count1 = 0;
	scanf("%d", &count);
	while (count--)
	{
		int n;
		scanf("%d", &n);
		if (n >= 5 && n <= 100)
		{
			memset(sign, -1, sizeof(sign));
			for (int i = 1; i <= n; i++)
			{
				for (int j = 1; j <= n; j++)
				{
					if (j%i == 0)
						sign[j] *= (-1);
				}
			}
			for (int i = 1; i <= n; i++)
			{
				if (sign[i] == 1)
				{
					count1++;
				}
			}
			printf("%d\n", count1);
			count1 = 0;
		}
		else
			exit(0);
	}
}

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