标签:标记 shu p12 while 递推 iostream super problem char
#include<bits/stdc++.h>
using namespace std;
int a[1001][1001];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
cin>>a[i][j];
for(int i=n-1;i>=1;i--)
for(int j=1;j<=i;j++)
if(a[i+1][j]>a[i+1][j+1])a[i][j]+=a[i+1][j];
else a[i][j]+=a[i+1][j+1];
cout<<a[1][1];
return 0;
}
#include<bits/stdc++.h>
using namespace std;
bool zhishu(int x){
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
bool huiwen(int y){
int s=0,y1=y;
while(y1!=0){
s=s*10+y1%10;
y1=y1/10;
}
if(s==y) return true;
else return false;
}
int main(){
int a,b,ans=0;
cin>>a>>b;
if(b>9999999)b=9999999;
for(int i=a;i<=b;i++){
if(i%2==0) continue;
if(huiwen(i)){
if(zhishu(i)) cout<<i<<endl;
else continue;
}
else continue;
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=100000;
int tot,Ans;
int v[N+5],prime[N+5],ans[N];
inline void get_prime(){
for(int i=2;i<=N;++i){
if(!v[i]){
prime[++tot]=i;
v[i]=i;
}
for(int j=1;j<=tot;++j){
if(prime[j]*i>N||prime[j]>v[i])break;
v[prime[j]*i]=prime[j];
}
}
}
inline bool pd_prime(int n){
if(n==1)return false;
for(int i=2;i*i<=n;++i)
if(n%i==0)return false;
return true;
}
inline void dfs(int now,int k,int n){
if(k>n){
ans[++Ans]=now;
return;
}
for(int i=9;i>=1;--i){
if(i%2==1&&i!=5){
if(pd_prime(now*10+i))dfs(now*10+i,k+1,n);
}
}
}
int main(){
get_prime();
int n=read();
if(n==1){printf("2\n3\n5\n7\n");return 0;}
if(n<=5){
int minn=pow(10,n-1),maxn=pow(10,n);
for(int i=1;i<=tot;++i){
if(prime[i]<minn)continue;
if(prime[i]>maxn)break;
int now=prime[i],bj=1;
for(int j=1;j<=n-1;++j){
now/=10;
if(pd_prime(now)==false){bj=0;break;}
}
if(bj)printf("%d\n",prime[i]);
}
}
else{
int cha=n-5;
for(int i=tot;i>=1;--i){
if(prime[i]<10000)break;
int now=prime[i],bj=1;
for(int j=1;j<=4;++j){
now/=10;
if(pd_prime(now)==false){bj=0;break;}
}
if(!bj)continue;
dfs(prime[i],1,cha);
}
for(int i=Ans;i>=1;--i)printf("%d\n",ans[i]);
}
return 0;
}
标签:标记 shu p12 while 递推 iostream super problem char
原文地址:https://www.cnblogs.com/PPXppx/p/11265172.html