链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
See Problem N for PDF statements.
NIO is playing a new game. In this game, NIO has a sword with attack power represented by an integer AAA. Initially, A=0A=0A=0. There are also nnn enemies in the game. NIO has to kill them in order, which means NIO must kill the (i−1)(i-1)(i−1)-th enemy before killing the iii-th enemy for each iii (2≤i≤n2\le i\le n2≤i≤n). For the iii-th enemy, NIO can kill it if and only if A≡i(modn)A\equiv i \pmod{n}A≡i(modn).
Fortunately, NIO can upgrade his sword at any moment for any number of times. Each time NIO upgrades his sword, he first chooses an integer xxx (0≤x≤90\le x\le 90≤x≤9), then changes the attack power of the sword from AAA to 10×A+x10\times A+x10×A+x.
NIO wants to minimize the number of times to upgrade the sword so that he can win the game as fast as possible. Can you help him to find the minimum times?
输入描述:
The first line contains one integer nnn (1≤n≤1061\le n\le 10^{6}1≤n≤106), indicating the number of enemies.
输出描述:
Output one integer indicating the minimum times to upgrade the sword.
示例1
输入
复制4
4
输出
复制4
4
说明
Here is a possible solution for the example: - The attack power of the sword when killing the first enemy can be 10×0+1=110\times0+1=110×0+1=1. - The attack power of the sword when killing the second enemy can be 10×1+4=1410\times1+4=1410×1+4=14. - The attack power of the sword when killing the third enemy can be 10×14+7=14710\times14+7=14710×14+7=147. - The attack power of the sword when killing the fourth enemy can be 10×147+2=147210\times147+2=147210×147+2=1472. So he needs to upgrade the sword at least four times.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool check(LL c,int l)
{
int co=0;
while(c)
{
co++;
c=c/10;
}
if(co<=l) return true;
else return false;
}
int main()
{
int n;
cin>>n;
if(n==1) //当只有一个敌人的时候,最少升级次数是0需要特判!
{
//1%1==0%1
puts("0");
return 0;
}
LL sum=0;
for(int i=1;i<=n;i++)
{
for(int L=1;L<=6;L++)
{
LL C=((i+1-(LL)i*(int)pow(10,L))%n+n)%n;
if(check(C,L)) //判断C的位数是否满足小于等于L位
{
sum+=L;
break;
}
}
}
cout<<sum<<endl;
return 0;
}