HDU 4432 Sum of divisors (进制模拟)
来源:互联网 发布:青少年近视调查数据 编辑:程序博客网 时间:2024/05/16 17:42
三个小函数
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;}
- HDU 4432 Sum of divisors (进制模拟)
- HDU-#4432 Sum of divisors(模拟)
- hdu 4432 Sum of divisors(模拟)
- HDU 4432(Sum of divisors)
- hdu 4432 Sum of divisors(暴力)
- HDU 4432Sum of divisors (进制转换模板)
- HDU 4432 Sum of divisors
- HDU:4432 Sum of divisors
- hdu 4432 Sum of divisors
- hdu 4432 Sum of divisors
- HDU 4432 Sum of divisors
- HDU 4432 Sum of divisors 质因数分解
- HDU—— 4432 Sum of divisors
- HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
- hdu4432 Sum of divisors(数论)
- hdu4432 Sum of divisors
- hdu4432 - Sum of divisors
- Sum of divisors
- C语言父子进程--waitpid的用法
- POJ3186:Treats for the Cows(区间DP)
- timus 1029. Ministry URAL 解题报告
- hdu2639(第k大值+01背包)
- HDU3342 Legal or Not 解题报告--拓扑排序
- HDU 4432 Sum of divisors (进制模拟)
- 利用navicat创建存储过程、触发器和使用游标的简单实例
- 新手的我们怎样定位自己的工作
- Factory Method 工厂方法(创建模式) 笔记
- SSH前台代码使用action的方法
- 软件自动安装管理器 -提供源码下载
- linux批量备份服务器配置文件和目录的脚本
- uva 10004
- 1752. Tree 2 (数据结构)