right prime numbers

K

Keith Thompson

Keith Thompson said:
Ksitami said:
function isprime(p:dword):boolean;
var i,s:dword;
[snip]

You posted a program in some language that closely resembles Pascal.
This is comp.lang.c. Your article is off-topic and inappriate here.

Fumble fingers. I meant "inappropriate", of course.
 
C

CBFalconer

Ksitami said:
function isprime(p:dword):boolean;

This isn't C.
var i,s:dword;

dword is undefined. Invalid Pascal.
begin
result:=false;

result is undefined. Invalid Pascal.
if p<2 then exit;

This isn't even Pascal.
if p<4 then begin
result:=true;
exit
end;
if (p mod 2=0) or (p mod 3=0) then
exit;
i:=5; s:=round(sqrt(p));
while i<=s do begin
if p mod i=0 then exit;
i+=2;
if p mod i=0 then exit;
i+=4
end;
result:=true
end;

const

Nor is this. The const section precedes the var section.
nsp=5;
sp:array[1..nsp] of dword=(1,3,5,7,9);

And this is an abortion. Certainly not legal Pascal nor C
procedure x(r:dword);
var i:dword;
begin
if isprime(r) then begin
writeln(r:9);
for i:=1 to nsp do
x(r*10 + sp);
end;
end;

begin
l:=0; lt:=0;
x(2); writeln(#10);


Illegal Pascal construct. Also illegal C.
x(3); writeln(#10);
x(5); writeln(#10);
x(7); writeln(#10);
writeln(lt);
end.

Epitome of uselessness.
 
K

Ksitami

/* Right-truncatable primes:
A zerofree number n is called right truncatable if n and all numbers
obtained by successively removing the rightmost digits are prime.
There are exactly 83 right truncatable primes in base 10.
The first few are 2, 3, 5, 7, 23, 29, 31, 37, 53, 59, 71, 73, 79, 233,
239, 293, 311, 313, 317, 373, 379, 593, 599, ... (Sloane's A024770),
the largest being the 8-digit number 73939133 (Angell and Godwin 1977).
-------------------
Weisstein, Eric W. "Truncatable Prime." From MathWorld--A Wolfram Web
Resource.
http://mathworld.wolfram.com/TruncatablePrime.html */

#include <stdio.h>
typedef unsigned long int uint;

uint isprime(uint p) {
if (p<2) return 0;
if (p<4) return 1;
if (0==p%2 || 0==p%3) return 0;
uint i=5;
while (i*i <=p ){
if (p%i==0) return 0;
i+=2;
if (p%i==0) return 0;
i+=4; }
return 1;
}

uint sp[]={1,3,5,7,9,0};
uint k=0;

void x(uint r){
uint i;
if (isprime(r)){
printf("%3d %9d\n", ++k, r);
for (i=0; sp!=0; i++)
x(r*10 + sp); }
}

int main(){
x(2); x(3); x(5); x(7);
getchar();
return 0;
}
 
K

Keith Thompson

Ksitami said:
uint isRTP(uint r) {
while (r>0) {
if (! isprime(r)) return 0;
r/=10; }
return 1; }

Please provide context when you post a followup. Google Groups
formerly had a bug that made this difficult; that bug has been fixed,
but <http://cfaj.freeshell.org/google/> still contains useful
information and links.

If you're going to post a chunk of code, you should say something
about it. I think I know what your isRTP function is trying to do,
but I don't know why you posted it.
 
S

simo

actually i origionally posted it in trying to fing a right prime which
is a number that all the numbers in the numbers is prime. say 573. the
3 5 and 7 are all prime. somehow the number needs to be broken down
divisibly by 10 for each character and then checked for prime.
simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top