hdu 4432 因子
来源:互联网 发布:js跨域上传文件 编辑:程序博客网 时间:2024/04/25 13:50
Sum of divisors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5052 Accepted Submission(s): 1673
Problem Description
mmm is learning division, she's so proud of herself that she can figure out the sum of all the divisors of numbers no larger than 100 within one day!
But her teacher said "What if I ask you to give not only the sum but the square-sums of all the divisors of numbers within hexadecimal number 100?" mmm get stuck and she's asking for your help.
Attention, because mmm has misunderstood teacher's words, you have to solve a problem that is a little bit different.
Here's the problem, given n, you are to calculate the square sums of the digits of all the divisors of n, under the base m.
But her teacher said "What if I ask you to give not only the sum but the square-sums of all the divisors of numbers within hexadecimal number 100?" mmm get stuck and she's asking for your help.
Attention, because mmm has misunderstood teacher's words, you have to solve a problem that is a little bit different.
Here's the problem, given n, you are to calculate the square sums of the digits of all the divisors of n, under the base m.
Input
Multiple test cases, each test cases is one line with two integers.
n and m.(n, m would be given in 10-based)
1≤n≤109
2≤m≤16
There are less then 10 test cases.
n and m.(n, m would be given in 10-based)
1≤n≤109
2≤m≤16
There are less then 10 test cases.
Output
Output the answer base m.
Sample Input
10 230 5
Sample Output
110112HintUse A, B, C...... for 10, 11, 12......Test case 1: divisors are 1, 2, 5, 10 which means 1, 10, 101, 1010 under base 2, the square sum of digits is 1^2+ (1^2 + 0^2) + (1^2 + 0^2 + 1^2) + .... = 6 = 110 under base 2.
Source
2012 Asia Tianjin Regional Contest
区域赛水题
取因子
这里用sqrt (n) 同时取两个因子,不需要标记
若一个是 i 另外一个就是 n / i ,因为是开根号就不用标记,不用怕之前已经被用过了
#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;long long n;int m;int a[100000000];long long pos;int main(){ //freopen("in.txt","r",stdin); while(scanf("%I64d%d",&n,&m)!=EOF) { long long ans=0; long long number=sqrt(n*1.0); long long x,i; for(i=1;i<=number;i++){ if(n%i==0){ x=i; while(x) { int t=x%m; ans+=t*t; x=x/m; } x=n/i; while(x) { int t=x%m; ans+=t*t; x=x/m; } } } if(n==1) ans=1; pos=0; while(ans) { a[pos++]=ans%m; ans/=m; } pos--; for(long long i=pos;i>=0;i--){ if(a[i]>9) printf("%c",a[i]+'A'-10); else printf("%d",a[i]); } puts(""); } return 0;}
0 0
- hdu 4432 因子
- HDU 4432 求因子+进制转换
- hdu 1215因子和
- hdu 4961 因子
- HDU 5428 【水+因子。。?】
- HDU 1215 因子相加
- HDU 4432 因子之和以及进制转换问题
- hdu 4139 质因子分解
- HDU 1299 求因子个数
- HDU 2574 素数因子数目
- HDU 1333 分解素数因子
- HDU 2421 质因子分解
- HDU 5108 最大素数因子
- hdu 2421 分解质因子
- hdu 5428(分解质因子)
- HDU 1164 找素数因子
- HDU 1058 素数因子DP
- hdu-1164涮素数+质因子分解
- 通州新城规划图 - 新通网http://www.xintongwang.com
- 用Lingo时查的一些东西
- Docker的Web UI管理:shipyard+swarm-(手动)安装&试用
- Ubuntu16.04+caffe+keras+tensorflow+GPU +matlab 安装资源查看
- CListCtrl 用法
- hdu 4432 因子
- VMWare网络设置的3中方式
- ubuntu搭建eclipse+svn
- 前端资源大杂烩(插件、工具、教程)
- tomcat7.070 源码及转成eclipse工程
- OC中的常用数据类型
- 工时估算的心得
- 创建一个 Framework 类型的静态库
- hdu 2065 "红色病毒"问题