[Zhengqing] [1775] The Monk's Troubles 1 - Is It a Prime?

Problem Description

Loading...

Problem Analysis

It’s been several days without posting to the blog again
At the time, I was also worn out by that one problem I hadn’t AC’d before
Thinking about it
since some problems were left unfinished from contests back then
so I’d better post these already-AC’d solutions first
and then write blog posts with peace of mind

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<math.h>
int main() {
	int n,i,m;
	while(scanf("%d",&n)!=EOF) {
		while(n--) {
			scanf("%d",&m);
			if(m==1)
				printf("No\n");
			else {
				for(i=2; i<=sqrt(m); i++)
					if(m%i==0) break;
				if(i>sqrt(m))
					printf("Yes\n");
				else
					printf("No\n");
			}
		}
	}
	return 0;
}

This uses the direct check method.

Problem link: [ZZULI] [1775] The Monk’s Troubles 1 — Is It a Prime?

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...