[ABC 100] B-Ringo's Favorite Numbers

B - Ringo's Favorite Numbers


Time limit : 2sec / Memory limit : 1000MB

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

  • D is 01 or 2.
  • N is an integer between 1 and 100 (inclusive).

[题目解释]

  给你两个数D和N,求第N个整除10D但不整除10D+1的数.

[题目解析]

  我们可以先预处理出10D后直接乘上N,但是N=100时乘上的是N+1.

[代码]

/*
    Name: Ringo's Favorite Numbers 
    Author: FZSZ-LinHua
    Date: 2018 06 16
    Exec time: 1ms
    Memory usage: 128KB
    Score: 200
    Algorithm: Brute-force 
*/
# include "iostream"
# include "cstdio" 

using namespace std;

int
    d,
    n;
    
long long
    mul=1ll; 

int main(){
    scanf("%d%d",&d,&n);     
    register int i;
    for(i=1;i<=d;i++){    //预处理出10^d 
        mul*=100; 
    }
    printf("%lld",(n+(n==100))*mul);    //等价于n=100时乘101否则乘上n 
    return 0; 
} 

猜你喜欢

转载自www.cnblogs.com/FJ-LinHua/p/9192816.html
ABC