HDU 4432 Sum of divisors (进制模拟)
模拟 of HDU sum 进制
2023-09-27 14:23:51 时间
三个小函数
getdiv(); 求因子
getsum(); 求平方和
change(); 转换成该进制
#include <cstdio> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int n,m,cnt,ans,num; int di[555555]; char str[111111]; void getdiv() { int up = sqrt(n); cnt = 0; for(int i=1; i<=up; i++) { if(n % i == 0) { di[cnt++] = i; if(n != i*i) di[cnt++] = n/i; } } } void getsum() { ans = 0; for(int i=0; i<cnt; i++) { int tmp = di[i]; while(tmp) { int t = tmp % m; ans += t*t; tmp = tmp / m; } } } void change() { num = 0; while(ans) { int t = ans % m; if(t >= 10) { str[num++] = t - 10 + 'A'; } else str[num++] = '0' + t; ans = ans / m; } } int main() { while(cin >> n >> m) { getdiv(); getsum(); change(); for(int i=num-1; i>=0; i--) { printf("%c",str[i]); } puts(""); } return 0; }
相关文章
- hdu4995 (不错的小模拟)
- C#调用接口注意要点 socket,模拟服务器、客户端通信 在ASP.NET Core中构建路由的5种方法
- OSG模拟鼠标事件影响操纵器
- 【BZOJ3638】Cf172 k-Maximum Subsequence Sum 线段树区间合并(模拟费用流)
- 【BZOJ3252】攻略 DFS序+线段树(模拟费用流)
- shell 模拟抽奖
- 1073 Scientific Notation (20 分)【难度: 一般 / 知识点: 字符串 模拟】
- jquery用div模拟一个下拉列表框
- 模拟实现strcat,用函数实现strcat及strcat的原理
- CodeForces 632C Grandma Laura and Apples (模拟)
- Selenium2学习-027-WebUI自动化实战实例-025-JavaScript 在 Selenium 自动化中的应用实例之三(页面滚屏,模拟鼠标拖动滚动条)
- python—模拟生成双色球号和大乐透号
- 《C#零基础入门之百识百例》(四)输入输出 -- 模拟登陆
- Redis持久化实践及灾难恢复模拟
- 物理模拟-动态水面