Matryoshka Dolls (Gym-102267C)

本文探讨了俄罗斯套娃数学问题,给出了求解最大嵌套数量的算法思路与源代码实现,通过暴力模拟的方法,计算给定尺寸和缩小倍数条件下,能够形成的最大套娃集合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description

Matryoshka Dolls are Russia's most popular souvenirs. They are sets of wooden figurines of decreasing size placed one inside another, though they have the same exact shape.

Our Matryoshka Doll is known to have an integer size SS which is the largest doll size in the collection, and each doll should have size X times less than the doll that holds it(size of the doll≤size of the doll that holds itXsize of the doll≤size of the doll that holds it X).

Given S and X, What is the maximum number of dolls that can be nested inside each other.

Input

The first and only line contains 2 integers S,X(1≤S≤109,2≤X≤109).

Output

Output one integer, the maximum number of dolls.

Examples

Input

10 2

Output

4

题意:给出 S、X 两个数,S 代表尺寸最大的套娃,如果想在一个套娃里放一个套娃,要求当前套娃的尺寸小于等于上一个套娃的尺寸除以 X

思路:暴力模拟即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
const int MOD = 1E9+7;
const int N = 10000000+5;
const int dx[] = {1,-1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main() {
    LL n,m;
    scanf("%lld%lld",&n,&m);

    LL res=0;
    while(n>0) {
        n/=m;
        res++;
    }
    printf("%lld\n",res);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值