HDU 4432 Sum of divisors (进制模拟)
2013-08-04 20:35
411 查看
三个小函数
getdiv(); 求因子
getsum(); 求平方和
change(); 转换成该进制
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 2012 Asia Tianjin Regional Contest
- 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 )
- hdu 4432 Sum of divisors
- HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
- HDU 4432 Sum of divisors (水题,进制转换)
- hdu 4432 Sum of divisors(十进制转其他进制)
- hdu 4432 Sum of divisors(模拟)
- B - Sum of divisors HDU - 4432
- HDU 2100 Lovekey 模拟26进制
- HDU:4432 Sum of divisors
- hdu-4432-Sum of divisors
- HDU—— 4432 Sum of divisors
- HDU 2100 (模拟进制加法)
- hdu 4432 Sum of divisors
- hdoj 4432 Sum of divisors