2019牛客暑期多校训练营(第七场)D Number

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值