Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 3 Prime mnbers satisty another property. If one has three integers m, n and

ID: 3745842 • Letter: P

Question

Part 3 Prime mnbers satisty another property. If one has three integers m, n and& ure say u and N are coagrueut modulo k if the remainder from dividing br s the same as the remainder from dividag n by k. We caa tba rite m-n( mod k). For instance, the mnbers 19 and 47 are congruent moodulo 7 since 19-2x7+5 and 47-6x7+5. The renainder from divisiou of both 19 an The congruence relation is preserved be asithmetic operatioos m mod k) andmod k), then m od d Prime ambers and congruences are related. There is a theoresn that states If p is a prime uambes, then foe auy integer poFor instauce, for p- 3, we oberve 11 od 28 2 mod 3) 64 4 mod 3) Therekre, P-3 satifies ap-a( mod P). Ine, we bare tried out 1,2,3, 4 although 4 bs sot gusranteed to work. This relation does aot la gea hold true for coanposite aumbers 1. Write a function listPrise Like tn, which accepts n ipt ud returas the list of prime-like ambens les than n using the congce relation check 2. Write a fanction nPrinelike (n) which accepts n as an inpst aad re turns the Erst n mamber of peime-like wmbess using the congrersce rela tion check 3. Compare the list of the first 200 primes fromm your nPrimes fanction an compare then with the output from your nPrimelike fanction. Wh coclusions can you draw? Your oamparison must be quantitative and abo avoid large output text. Use bt oonprebeskas or wite your evde to filter out elements which may be different in the two lists I yon don see any dierence push harder to n-500.ook up Carmikal aes Tip: To caleulate the remninder of the division off o with&,e(a kFor speed, you can also use powta, n,k) which does the se The anction pow (a,n) just returns a

Explanation / Answer

Part1:

C language

#include<stdio.h>

int min(int a, int b) {
if (a > b) {
return b;
}
return a;
}
void isPrimeLike(int n) {
int i;
int j;
int k;
for (i = 1; i < n; i++) {
for (j = 1; j < n; j++) {
for (k = 2; k <= min(i, j); k++) {
if(i % k == j % k && i != j && (i % j != 0&& j % i != 0)) {
printf("%d %d %d ",i,j,k);
}
}
}
}
}
int main()
{
int n;
scanf("%d",&n);
isPrimeLike(n);
return 0;
}

Note: m % k == n % k

Part 2:

#include<stdio.h>
#include<limits.h>
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int min(int a, int b) {
if (a > b) {
return b;
}
return a;
}

void isPrimeLike(int n) {
int i;
int j;
int k;
set <int> s;
for (i = 1; i < INT_MAX; i++) {
for (j = 1; j < INT_MAX; j++) {
for (k = 2; k <= min(i, j); k++) {
if(i % k == j % k && i != j && (i % j != 0&& j % i != 0)) {
//printf("%d %d %d ",i,j,k);
s.insert(i);
s.insert(j);
}
}
}
}
set<int> :: iterator it;
vector<int> v;
for (it = s.begin(); it != s.end(); it++) {
v.push_back(*it);
}
sort(v.begin(),v.end());
for(i = 0; i < n; i++) {
printf("%d ", v[i]);
}
printf(" ");
}
int main()
{
int n;
scanf("%d",&n);
isPrimeLike(n);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote