/*
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1996 Accepted Submission(s): 679 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. 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. Output
Output the answer base m. Sample Input
10 2
30 5 Sample Output
110
112
Hint Use 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. */
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 26000
int a[maxn];
int sum;
int k,i,j,tmp;
char b[maxn];
void yinzi(int n)
{
k=;
for(i=; i*i<=n; i++)
{
if(n%i==)
{
a[k++]=i;
if(i!=n/i)
a[k++]=n/i;
}
}
}
void change(int m)
{
sum=;
for(i=; i<k; i++)
{
while(a[i])
{
tmp=a[i]%m;
sum+=tmp*tmp;
a[i]=a[i]/m;
}
}
}
void rechange(int x,int m)
{
j=;
stack<char> st;
while(x)
{
tmp=x%m;
if(tmp>=)
st.push('A'+tmp-);
//b[j++]='A'+tmp-10;
else
st.push(tmp+'');
// b[j++]=tmp+'0';
x=x/m;
}
while(!st.empty())
{
cout<<st.top();
st.pop();
}
/*if(x)
{
rechange(x/m,m);
tmp=x%m;
if(tmp>=10)
printf("%c",'A'+tmp-10);
else
printf("%d",tmp);
}*/
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{ yinzi(n);
change(m);
rechange(sum,m);
//cout<<" j= "<<j<<endl;
/*for(i=j-1;i>=0;i--)
{
//printf("%c",b[i]);
cout<<b[i];
}*/
printf("\n");
}
return ;
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;
int cal;
void Base(int n,int m){
if(n)
{
Base(n/m,m);
cal+=(n%m)*(n%m);
}
}
void out(int n,int m){
if(n){
out(n/m,m);
if(n%m>)
printf("%c",'A'+(n%m)-);
else printf("%d",n%m);
}
}
int main(){ int n,m;
int i,k,sum;
while(scanf("%d %d",&n,&m)!=EOF){
//k=sqrt(n+1.0);
sum=;
for(i=;i*i<n;i++)
{
if(n%i==){
cal=;
Base(i,m);
sum+=cal;
cal=;
Base(n/i,m);
sum+=cal;
}
}
if(i*i==n){
cal=;
Base(i,m);
sum+=cal;
}
out(sum,m);
printf("\n");
}
return ;
}
/*错误代码,求解*/
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 260000
int a[maxn];
int sum;
int k,i,tmp;
char b[maxn];
void yinzi(int n)
{
k=;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
a[k++]=i;
if(i!=n/i)
a[k++]=n/i;
}
}
}
void change(int m)
{
sum=;
for(i=;i<k;i++)
{
while(a[i])
{
tmp=a[i]%m;
sum+=tmp*tmp;
a[i]=a[i]/m;
}
}
} int main()
{
int n,m,x,j;
while(~scanf("%d%d",&n,&m))
{
yinzi(n);
change(m);
// rechange(sum,m);
x=sum;
j=;
while(x)
{
tmp=x%m;
if(tmp>=)
b[j++]=tmp-+'A';
else
b[j++]=tmp+'';
x=x/m;
}
for(i=j-;i>=;i--)
{
printf("%c",b[i]);
}
printf("\n");
}
return ;
}

hdu-4432-Sum of divisors的更多相关文章

  1. hdu 4432 Sum of divisors(十进制转其他进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...

  2. HDU 4432 Sum of divisors (水题,进制转换)

    题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...

  3. HDU 4432 Sum of divisors (进制模拟)

    三个小函数 getdiv();        求因子 getsum();     求平方和 change();     转换成该进制 #include <cstdio> #include ...

  4. hdu4432 Sum of divisors(数论)

    Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU4432 Sum of Divisors

    涉及知识点: 1. 进制转换. 2. 找因子时注意可以降低复杂度. Sum of divisors Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  6. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  7. hdu 1258 Sum It Up(dfs+去重)

    题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...

  8. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  9. HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)

    C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  10. HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

    Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status  ...

随机推荐

  1. python 获取5天前的日期

    from datetime import date, timedelta dt = date.today() - timedelta() print('Current Date :',date.tod ...

  2. python 判断列表字符串元素首尾字符是否相同

    def match_words(words): ctr = for word in words: and word[] == word[-]: ctr += return ctr print(matc ...

  3. Android-----------广告图片轮播控件

    Banner广告图片轮播控件,支持无限循环和多种主题,可以灵活设置轮播样式.动画.轮播和切换时间.位置.图片加载框架等! 很多Android APP中都有广告栏,我也用过很多次了,特来写一篇博文. 先 ...

  4. vue/webpack的一些小技巧

    都知道我比较懒,今天给大家分享的就是如何让自己省事. 一.vue修改打包后的结构(不知道怎么描述合理,看效果图) /config/index.js 默认的: 修改的:(顺手修改了打包后的文件名) 这样 ...

  5. 《剑指offer》习题解答(C/C++)

    1.二维数组中的查找 /* 题目:在一个二维数组中,没一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序. 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...

  6. 045——VUE中组件之父组件使用scope定义子组件模板结构

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 数据库 update select 多列操作

    最常用的update语法是:  UPDATE <table_name>  SET <column_name1> = <value>, SET <column_ ...

  8. Java——抽象类、接口

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  9. 《转》深入理解Activity启动流程(二)–Activity启动相关类的类图

    本文原创作者:Cloud Chou. 出处:本文链接 本系列博客将详细阐述Activity的启动流程,这些博客基于Cm 10.1源码研究. 在介绍Activity的详细启动流程之前,先为大家介绍Act ...

  10. 【python】venv使用

    virtualenvwrapper 比 virualenv 好用一些. 准备 export WORKON_HOME=~/venv source /usr/bin/virtualenvwrapper.s ...