hdu 4432 Sum of divisors(模拟)
来源:互联网 发布:php java混合 编辑:程序博客网 时间:2024/05/17 02:27
水题。
先根号n分解因数,再进行简单的进制转换。
坑:有10~16进制情况,要输出ABCDEF,开始没看见wa了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>using namespace std;#define LL long longvector <int> Div;char c[10000];void solve(LL n){ int k=sqrt(n); for(int i=1;i<=k;i++){if(n%i==0){Div.push_back(i);if(i!=(n/i)) Div.push_back(n/i);} }}LL Get(LL n,int m){LL res=0; while(n>0){int tmp=n%m;LL T=tmp*tmp;res+=T;n/=m; } return res;}int change(LL n,int m){ LL res=0;int i=0; while(n>0){LL tmp=n%m;char tc;if(tmp==10) tc='A';else if(tmp==11) tc='B';else if(tmp==12) tc='C';else if(tmp==13) tc='D';else if(tmp==14) tc='E';else if(tmp==15) tc='F';else tc=char(tmp+'0');c[i]=tc;n/=m;i++; } i--; return i;}int main(){int m;LL n;while(~scanf("%I64d%d",&n,&m)){Div.clear();solve(n);LL res=0;for(int i=0;i<Div.size();i++){res+=Get(Div[i],m);}int len=change(res,m);for(int i=len;i>=0;i--){printf("%c",c[i]);}printf("\n");}return 0;}
0 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 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 4432Sum 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
- 北京理工大学研究生赴台参会攻略
- Jenkins界面Jelly入门
- 动态代理 Proxy InvocationHandler学习
- HDU 4115 Eliminate the Conflict(2-sat)
- 共享机遇,就在大数据时代
- hdu 4432 Sum of divisors(模拟)
- Sqlserver查询数据库文件大小和剩余空间
- C#上机实验
- 王立平--scard0与scard1分别指的是什么?以及路径获取
- mysql简单的操作
- OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用
- 第九周项目5-程序填充题 .
- setupapi.h和setupapi.lib該如何使用
- 第九周项目六(解奥数题)