首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
huanghu
2024年3月13日 00:06
素数判定 题解:
P1102
回复 0
|
赞 0
|
浏览 857
#include<stdio.h> #include<iostream> using namespace std; bool ss(int a){ for(int i = 2; i<=a/2; i++){ if(a%i == 0){ return false; } } return true; } //给你两个数a、b,现在的问题是要判断这两个数组成的区间内共有多少个素数 int main(){ int a,b; while...
lingdongyang
2024年3月10日 11:31
素数判定 题解:
P1102
回复 0
|
赞 1
|
浏览 884
#include<stdio.h> #include<math.h> int main() { int a, b; while (scanf("%d%d", &a, &b) != EOF) { int cnt = 0; if (a > b) { int t = b; b = a; a = t; } for (int i = a; i <= b; i++) {//从a到b之间每个数进行判定 int flag = 0; for (int j = 2; j <...
orderrr
2024年3月4日 15:17
素数判定 题解:c 多谢评论区的指正,需要提前判断a,b谁大谁小
P1102
回复 0
|
赞 0
|
浏览 777
#include <stdio.h> #include <math.h> int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { if (b < a) { int temp = a; a = b; b = temp; } int cnt = 0; // 记录素数的个数 ...
小王桐学
2024年2月6日 16:39
素数判定 题解:C
P1102
回复 0
|
赞 0
|
浏览 718
#include <stdio.h> #include <math.h> int isPrimary(int n) { int i; for(i = 2; i <= sqrt(n); i++) if(n % i == 0) break; if(i > sqrt(n)) return 1; else return 0; } int Primary(int a,int b) { int i,count = 0; if(a > b) { i = a; a = b; b = ...
peterzhou
2023年7月30日 13:34
素数判定 题解:简洁快速
P1102
回复 0
|
赞 2
|
浏览 1.1k
#include <bits/stdc++.h> using namespace std; int isprime(int n) { vector<int> a(n, 0); int cnt = 0; a[0] = a[1] = 1; for (int i = 2; i < n; i++) { if (!a[i]) { &...
Hegel
2023年3月22日 20:32
输出区间[a,b]内的素数
P1102
回复 0
|
赞 0
|
浏览 2.6k
#include <iostream> #include <cmath> using namespace std; bool Jud(int a) { if (a <= 1) return false; if (a == 2) return true; for (int i = 2; i < sqrt(a) + 1; i++) if (a % i == 0) return false; return true; } int main() { int a,b; while(cin>&g...
huangdashuaige
2023年2月20日 16:20
P1102 素数判定
P1102
回复 0
|
赞 1
|
浏览 3.7k
#include <iostream> #include <math.h> using namespace std; int sw(int &a,int &b){ //该函数用于保障a<b int t; if(a>b){ t=a;a=b;b=t; } } int main(){ &...
阔赛英
2023年2月5日 19:38
素数的倍数一定不是素数
P1102
回复 0
|
赞 0
|
浏览 3.3k
#include <iostream> using namespace std; int main() { int a, b; while (cin >> a >> b) { int min, max, sum=0; if (a > b) { min = b; max = a; } else { min = a; max = b; } ...
My_opt
2022年4月26日 13:03
c++
P1102
回复 0
|
赞 0
|
浏览 5.5k
#include <iostream> using namespace std; int a, b; bool is_prime(int x) { for (int i = 2; i <= x / i; i ++ ) if (x % i == 0) return false; return true; } int main() { while (cin >> a >> b) { int cnt = 0; for (int i = min(a, b); i <= max(a, ...
AnferNi
2021年6月24日 11:50
素数筛选办法
P1102
回复 0
|
赞 0
|
浏览 6.4k
#include <iostream> #include <algorithm> #include <string> #include <bits/stdc++.h> using namespace std; const int maxn = 1000000+5; int prime[maxn]; void getPrime(){ memset(prime,0,sizeof(prime)); for(int i=2;i<=maxn;i++){ &n...
1
2
3
题目
素数判定
题解数量
22
发布题解
在线答疑
热门题解
1
素数判定 题解:素数定义+整体思路
2
素数判定 题解:为什么有错误啊佬们,dev c++能通过
3
素数判定 题解:简洁快速
4
素数判定 (试除法 O(n*sqrt(n))题解:
5
素数判定 题解:
6
素数判定 题解:
7
[c]易错点为:if a>b则需要交换a与b的值
8
素数判定 题解:
9
素数判定 题解:
10
素数判定 题解:简洁易懂