D Number
链接:https://ac.nowcoder.com/acm/contest/887/D
题目描述
I have a very simple problem for you. Given a positive integeter n\ (1 \leq n \leq 1000000)n (1≤n≤1000000) and a prime number p (2≤p≤1000000), your job is to output a positive number which is divisible by and has exactly digits. Please output “T_T” if you can not find such number.
输入描述:
The first line of the input file contains two integers (1≤n≤1000000) and p (2≤p≤1000000). p is a prime number.
输出描述:
Output one number (without leading zeros) or “T_T”
示例1
输入
2 5
输出
10
示例2
输入
1 11
输出
T_T
示例3
输入
5 2
输出
10000
题意
找到一个 n 位数的素数 p 的倍数,如果没有,则输出“ T_T ”
分析
如果给出的素数位数大于所要求的位数,那么,显然,该数不存在
若是存在,我们只需要在该素数后面补 0 即可,缺少几位则补几个 0 (补0显然满足倍数关系)
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
char p[8];
cin>>n;
scanf("%s",&p);
int x=strlen(p);
if(n<x)printf("T_T\n");
else{
n-=x;
for(int i=0;i<x;i++)cout<<p[i];
for(int i=0;i<n;i++)cout<<'0';
cout<<endl;
}
return 0;
}