题目链接:uva 11256 - Repetitive
Multiple
题目大意:给定一个数n,要求找到最小的k,使得k∗n为题目中定义的重复数字.
解题思路:枚举k∗n的循环节长度,比如当前枚举为2,那么一次判断u=1001,1001001,1001001001
...,取d = gcd(n,u), 那么k = u / d, a = n / d (因为n∗k=u∗a)并且保证a的长度为2,所以k和a要同时扩大相应倍数。枚举过程中为何k。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e18+1;
ll N, ten[20];
void init () {
ten[0] = 1;
for (int i = 1; i < 20; i++)
ten[i] = ten[i-1] * 10;
}
inline ll gcd (ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
inline int tenbit (ll n) {
int cnt = 0;
while (n) {
n /= 10;
cnt++;
}
return cnt;
}
ll solve () {
ll ans = INF;
int bit = tenbit(N);
if (bit == 1)
return 11L;
for (int i = 1; i <= bit; i++) {
ll u = ten[i] + 1;
while (true) {
ll d = gcd(N, u);
ll a = N / d;
ll k = u / d;
if (a < ten[i]) {
if (a < ten[i-1])
a = ten[i-1] / a + (ten[i-1] % a ? 1 : 0);
else
a = 1;
if (a * k < ans)
ans = k * a;
}
if (INF / u < ten[i])
break;
u = u * ten[i] + 1;
}
}
return ans;
}
int main () {
init();
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%lld", &N);
while (N >= 1e9);
printf("%lld\n", solve() * N);
}
return 0;
}
分享到:
相关推荐
Design of robust discrete-time observer-based repetitive-control system
与https://www.mathworks.com/matlabcentral/fileexchange/56448-particle-swarm-based-repetitive-spline-compensator类似的故事,但这次使用混合学习公式。 这个模型是由我的同事 Karol Basinski 开发的。 有关更...
实现了http://www.mathworks.com/matlabcentral/fileexchange/49023-b-spline-based-repetitive-neurocontroller中描述的一些修改。 由 Michal Malkowski 为...
bzip2 [-cdfhkLstvVz][--repetitive-best][--repetitive-fast][- 压缩等级][要压缩的文件] 参数: -c或–stdout 将压缩与解压缩的结果送到标准输出。 -d或–decompress 执行解压缩。 -f或–force bzip2在压缩或解...
Matlab集成的c代码ACSC 用于非重复扫描固态LiDAR和摄像头系统的自动外部校准。 系统架构 1.依赖 已在Ubuntu 16.04 64位和Ubuntu 18.04 64位上进行测试。...ROS(经过动力学/旋律测试) ...我们开发了一种实用的ROS工具来...
Acceleration-level repetitive motion planning of redundant planar robots solved by a simplified LVI-based primal-dual neural network
Mac, and Linux provides rock-solid terminal emulation for computing professionals, raising productivity with advanced session management and a host of ways to save time and streamline repetitive ...
Design of a discrete-time output-feedback based repetitive-control system
difference of repetitive and non-repetitive Big Data. Profound differences between repetitive and non-repetitive Big Data is herein called the “great divide.” This book is worth buying for no other ...
Design of a robust observer-based modified repetitive-control system
An ideal error dynamics is formed, and a repetitive controller is desirable to avoid system chattering, and the compensation to reject disturbances is introduced. The steady-state error band, ...
Design of a modified repetitive-control system with dynamic output-feedback controller
该文件包含支持 DOP 的 PSO 的实现,用于在电机惯性突然变化的情况下调整控制器... 基于http://www.mathworks.com/matlabcentral/fileexchange/47947-adaptive-optimal-control-for-repetitive-processes 的想法和开发
针对周期参考/干扰信号下的不确定离散时间系统,提出一种基于吸引律的重复控制方法,在吸引律中“嵌入”干扰抑制措施,,构造理想误差动态,并基于此设计重复控制器。文中推导出单调减区域、绝对吸引层和稳态误差带...
Fabricated vessel-mimetic microtubes are essential for delivering sufficient nutrient to engineered composite tissues. In this paper, vascular-like microtubes are engineered by automated assembly of ...
MATLAB程序m文件和simulink程序,用粒子群算法做控制器去优化迭代学习控制,鲁棒性好,且迭代精度高,有PDF详细解释
搜索算法类似于https://www.mathworks.com/matlabcentral/fileexchange/64056-hybrid-swarm-based-repetitive-controller-with-adaptive-forgetting-for-a-grid-tie-converter 。 如果您对PV建模感兴趣,还可以使用...
SAP REM repetitive manufaturing SAP REM repetitive manufaturing SAP REM repetitive manufaturing
IAR Repetitive Avalanche Current 1 A Current decaying linearly to zero in 1 μsec (Per Leg) Frequency limited by TJ max. VA = 1.5 x VR typical A Parameters 60CPQ Units Conditions Following any rated ...