Sequence with Digits

本文介绍了一种递归数列的计算方法,该方法通过定义数列的每一项为前一项加上最小和最大数位的乘积来生成数列。文章详细解释了如何通过给定的初始值和目标项数来计算数列的特定项。

Let’s define the following recurrence : an+1=an+minDigit(an)⋅maxDigit(an).an+1=an+minDigit(an)⋅maxDigit(an).Here minDigit(x)minDigit(x) and maxDigit(x)maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes.
For examples refer to notes.Your task is calculate aK for given a1 and K.
Input
The first line contains one integer t(1≤t≤1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a1 and K (1≤a1≤1018, 1≤K≤1016) separated by a space.
Output
For each test case print one integer aKaK on a separate line.
Example
input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
ootput
42
487
519
528
544
564
588
628
Note
a1=487
a2=a1+minDigit(a1)⋅maxDigit(a1)=487+min(4,8,7)⋅max(4,8,7)=487+4⋅8=519
a3=a2+minDigit(a2)⋅maxDigit(a2)=519+min(5,1,9)⋅max(5,1,9)=519+1⋅9=528
a4=a3+minDigit(a3)⋅maxDigit(a3)=528+min(5,2,8)⋅max(5,2,8)=528+2⋅8=544
a5=a4+minDigit(a4)⋅maxDigit(a4)=544+min(5,4,4)⋅max(5,4,4)=544+4⋅5=564
a6=a5+minDigit(a5)⋅maxDigit(a5)=564+min(5,6,4)⋅max(5,6,4)=564+4⋅6=588
a7=a6+minDigit(a6)⋅maxDigit(a6)=588+min(5,8,8)⋅max(5,8,8)=588+5⋅8=628

#include<stdio.h>
int fmax(int n)
{
 int res=n%10;
 while(n)
 {
  if(res<n%10)
  {
   res=n%10;
  }
  n=n/10;
 }
 return res;
}
int fmin(int n)
{
 int res=n%10;
 while(n)
 {
  if(res>n%10)
  {
   res=n%10;
  }
  n=n/10;
 }
 return res;
}
int fmn(int n)
{
 return n+fmax(n)*fmin(n);
}
int main()
{
 int t=0;
 scanf("%d",&t);
 while(t--)
 {
  int a1,k=0;
  scanf("%d%d",&a1,&k);
  for(int i=1;i<k;i++)
  {
   a1=fmn(a1);
  }
  printf("%d\n",a1);
 }
}
roslaunch stdRobEnvironment stdRobEnvironmentLaunch.launch WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. ... logging to /home/ros1/.ros/log/761835b8-6248-11f0-a7a5-b578a8a7bb4a/roslaunch-ros1-PC-1247594.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. started roslaunch server http://ros1-PC:35915/ SUMMARY ======== PARAMETERS * /gazebo/enable_ros_network: True * /robot_description: <?xml version="1.... * /robot_state_publisher/publish_frequency: 50.0 * /rosdistro: noetic * /rosversion: 1.17.4 * /use_sim_time: True NODES / gazebo (gazebo_ros/gzserver) gazebo_gui (gazebo_ros/gzclient) joint_state_publisher (joint_state_publisher/joint_state_publisher) robot_state_publisher (robot_state_publisher/robot_state_publisher) spawn_urdf (gazebo_ros/spawn_model) auto-starting new master process[master]: started with pid [1247603] ROS_MASTER_URI=http://localhost:11311 setting /run_id to 761835b8-6248-11f0-a7a5-b578a8a7bb4a WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. process[rosout-1]: started with pid [1247613] started core service [/rosout] process[gazebo-2]: started with pid [1247620] process[gazebo_gui-3]: started with pid [1247624] process[spawn_urdf-4]: started with pid [1247629] process[joint_state_publisher-5]: started with pid [1247631] process[robot_state_publisher-6]: started with pid [1247632] WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdPPONavi" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "stdRobEnvironment" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. /opt/ros/noetic/lib/python3/dist-packages/actionlib/goal_id_generator.py:46: SyntaxWarning: invalid escape sequence '\p' * \param name Unique name to prepend to the goal id. This will /opt/ros/noetic/lib/python3/dist-packages/actionlib/goal_id_generator.py:56: SyntaxWarning: invalid escape sequence '\p' * \param name Set the name to prepend to the goal id. This will Traceback (most recent call last): File "/opt/ros/noetic/lib/gazebo_ros/spawn_model", line 34, in <module> from tf.transformations import quaternion_from_euler File "/opt/ros/noetic/lib/python3/dist-packages/tf/__init__.py", line 31, in <module> from .listener import Transformer, TransformListener, TransformerROS File "/opt/ros/noetic/lib/python3/dist-packages/tf/listener.py", line 29, in <module> import numpy ModuleNotFoundError: No module named 'numpy' [INFO] [1752672381.291303812]: Finished loading Gazebo ROS API Plugin. [INFO] [1752672381.291818163]: waitForService: Service [/gazebo/set_physics_properties] has not been advertised, waiting... [INFO] [1752672381.325034175]: Finished loading Gazebo ROS API Plugin. [INFO] [1752672381.325560149]: waitForService: Service [/gazebo_gui/set_physics_properties] has not been advertised, waiting... [spawn_urdf-4] process has died [pid 1247629, exit code 1, cmd /opt/ros/noetic/lib/gazebo_ros/spawn_model -urdf -model turtlebot3_waffle_pi -x 1.0 -y 1.0 -z 0.0 -param robot_description __name:=spawn_urdf __log:=/home/ros1/.ros/log/761835b8-6248-11f0-a7a5-b578a8a7bb4a/spawn_urdf-4.log]. log file: /home/ros1/.ros/log/761835b8-6248-11f0-a7a5-b578a8a7bb4a/spawn_urdf-4*.log [INFO] [1752672381.920386401, 767.293000000]: waitForService: Service [/gazebo/set_physics_properties] is now available. [INFO] [1752672381.951258315, 767.323000000]: Physics dynamic reconfigure ready. ^C[robot_state_publisher-6] killing on exit [joint_state_publisher-5] killing on exit [gazebo_gui-3] killing on exit [gazebo-2] killing on exit ^C[gazebo_gui-3] escalating to SIGTERM [rosout-1] killing on exit [master] killing on exit shutting down processing monitor...
07-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【执珪】瑕瑜·夕环玦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值