输出样例:
Case 1
10 189999
10 279999
10 369999
10 459999
10 549999
10 639999
10 729999
10 819999
10 909999
Case 2
No Solution
这个题。。之前总结那个两个坑我觉得我说明白了
而且题目说的很清楚 先按n增序排 再按A增序排
所以老老实实排序吧 满分要紧呀
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct ans{
int shuzihe;
int shu;
};
int gcd(int a,int b){
if(a%b==0) return b;
else return gcd(b,a%b);
}
int isprime(int n){
if(n<=2) return 0;
for(int i=2;i*i<=n;i++){
if(n%i==0) return 0;
}
return 1;
}
int dsum(int n){
int sum=0;
while(n!=0){
sum=sum+n%10;
n=n/10;
}
return sum;
}
bool cmp(ans a,ans b){
if(a.shuzihe!=b.shuzihe) return a.shuzihe<b.shuzihe;
else return a.shu<b.shu;
}
int main(){
int N;scanf("%d",&N);
int k,m;
ans c[10000]={0};
for(int i=0;i<N;i++){
memset(c,0,sizeof(c));
scanf("%d %d",&k,&m);
int min=pow(10,k-1);
long long max=min*10-1;
int count=0;
printf("Case %d\n",i+1);
if(isprime(m)==1){
printf("No Solution\n");
continue;
}
for(int j=min+9;j<=max;j=j+10){
int num=0;
if(dsum(j)==m){
if(isprime(gcd(dsum(j+1),m))==1){
c[count].shuzihe=dsum(j+1);
c[count].shu=j;
count++;
}
}
}
if(count==0) printf("No Solution\n");
sort(c,c+count,cmp);
for(int j=0;j<count;j++){
printf("%d %d\n",c[j].shuzihe,c[j].shu);
}
}
return 0;
}