当前位置:网站首页>1015 reversible primes (20 points)
1015 reversible primes (20 points)
2022-06-30 14:55:00 【Xue Dongjing】
1015 Reversible Primes (20 branch )
The question
Give two integers at a time ,N,D, Ask for judgment N and N stay D Are all prime numbers after base down flip .
Ideas
The prime sieve judges prime numbers , Right again N stay D Base down flip . First judge N Is it a prime , Then judge whether the inverted number is a prime number , Be careful 0 and 1 Not prime .
Code
#include<stdio.h>
#include<string.h>
int prime[1000000];
bool number[1000000];
void Prime(int n)
{
int count=0;
memset(number,0,sizeof(number));
number[1]=1;
number[0]=1;
for(int i=2; i<=n; i++){
if(!number[i]){
prime[count++]=i;
}
for(int j=0;j<count&&i*prime[j]<=n;j++){
number[i*prime[j]]=1;
if(i%prime[j]==0){
break;
}
}
}
}
int reverse(int N,int D)
{
int x[100],cnt=0,sum=0,weight=1;
while(N){
x[cnt++]=N%D;
N/=D;
}
for(int i=cnt-1; i>=0; i--){
sum+=x[i]*weight;
weight*=D;
}
return sum;
}
int main()
{
int N,D,x;
Prime(100007);
while(scanf("%d",&N)){
if(N<0){
break;
}
scanf("%d",&D);
if(!number[N]){
x=reverse(N,D);
if(!number[x]){
printf("Yes\n");
}else{
printf("No\n");
}
}else{
printf("No\n");
}
}
return 0;
}
边栏推荐
- 【BUUCTF】 EasySql
- Determine the number of digits of an integer in MATLAB (one line of code)
- 1134: Legal C identifier query
- Greedy interval problem (5)
- 浅析卧式加工中心上不规则台阶孔存在问题
- For loop and promise to solve the problem of concurrent callback
- Ctfshow getting started with the web (ThinkPHP topic)
- Implement a long-click list pop-up box on apiccloud
- Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
- Hbuilder most commonly used and full shortcut key set
猜你喜欢

CCF Z-scan (full mark code + problem solving ideas) 201412-2

Solve the problem that codeblocks20.03 on win11 cannot run for the first time

Determine the number of digits of an integer in MATLAB (one line of code)

Component communication mode

Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)

Shift operator (detailed)

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

Computer screenshot how to cut the mouse in

Thinkphp5 log file contains trick

ThinkPHP v3.2 comment annotation injection write shell
随机推荐
Programming exercises: whole point and circle (solution ideas and code implementation)
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
立式加工中心调试的步骤
Double pointer circular linked list
2021 geek challenge Web
V3 01_ Welcome
立式加工中心的数控加工对刀具使用基本要求
Error $(...) size is not a function
Greedy two-dimensional array sorting
Greedy interval problem (5)
2021-07-14 mybaitsplus
Examples of bubble sorting and matrix element screening in MATLAB
DiceCTF - knock-knock
Bucket sorting (C language)
Working principle and fault treatment of cutting cylinder in CNC machining center
先锋期货安全么?现在期货开户都是哪些流程?期货手续费怎么降低?
分布式--OpenResty+lua+Redis
Detailed explanation of settimeout() and setinterval()
How to use Alibaba Vector Icon
Programming exercises: special numbers (problem solving ideas + code implementation)