题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和。

析:按它的要求做就好,注意的是,是因数,不可能有重复的。。。比如4的因数只有一个2,还有就是输出10进制以上的,要用AB。。

但我用的是ab。。又没读好题。。。。活该WA了好几次。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int a[70]; int solve(int x){
int ans = 0;
while(x){
ans += (x % m) * (x % m);
x /= m;
}
return ans;
} int main(){
while(scanf("%d %d", &n, &m) == 2){
int t = sqrt(n+0.5);
int ans = 0;
for(int i = 1; i <= t; ++i){
if(n % i == 0){
ans += solve(i);
if(n / i != i) ans += solve(n/i);
}
}
int cnt = 0;
while(ans){
a[cnt++] = ans % m;
ans /= m;
}
for(int i = cnt-1; i >= 0; --i)
if(a[i] < 10) printf("%d", a[i]);
else printf("%c", 'A'+a[i]-10);
printf("\n");
}
return 0;
}

HDU 4432 Sum of divisors (水题,进制转换)的更多相关文章

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

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

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

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

  3. HDU 2031 进制转换(10进制转R进制)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. HDU5053the Sum of Cube(水题)

    HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...

  5. 进制转换(NOIP2000&NOIP水题测试(2017082301))

    题目链接:进制转换 这题得明白其中的数学方法,明白后就不难了. 那么我们应该怎么计算呢? 其实也很简单. 我们依然采取辗转相除法. 但是,对于负的余数,我们需要进行一些处理. 我们怎么处理呢? 很简单 ...

  6. HDU 2097 Sky数 进制转换

    解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...

  7. poj1220:高精度进制转换模板题

    今天撸3708  一直奇怪的re 就先放下了,写这个题的过程中学习了一个高精度进制转换,用这个模板写了1220 记录一下: #include <iostream> #include < ...

  8. PAT甲级 进制转换题_C++题解

    进制转换题 PAT (Advanced Level) Practice 进制转换题 目录 <算法笔记> 重点摘要 1015 Reversible Primes (20) 1019 Gene ...

  9. hdu 2031 进制转换(栈思想的使用)

    进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

随机推荐

  1. uva12169 Disgruntled Judge

    扩展欧几里得. 枚举a,根据x1,x3和递推式可得. (a+1)*b-k*mod=f[3]-a*a*b. 通过扩展欧几里得求出b. 带入原式进行计算. #include<cstdio> # ...

  2. android gallery 自定义边框+幻灯片

    最近在项目中用到图片轮播,试了Gallery,ViewFlipper,ViewPager,感觉Gallery最符合需求,但是Gallery的系统边框很难看,项目中要求用自己的背景图片. 下面来看一下使 ...

  3. hdu 4674 Trip Advisor(缩点+倍增lca)

    花了一天半的时间,才把这道题ac= = 确实是道好题,好久没敲这么长的code了,尤其是最后的判定,各种销魂啊~ 题目中给出的条件最值得关注的就是:每个点最多只能在一个环内->原图是由一个个边连 ...

  4. I.MX6 linux Qt 同时支持Touch、mouse

    /***************************************************************************** * I.MX6 linux Qt 同时支持 ...

  5. LT1619EMS8 锂电池 升压电路分析

    LT1619EMS8 锂电池 升压电路分析 本文主要是分析LT1619EMSB锂电池升压芯片电路,知道其大致是怎么工作的,其中的一些电阻该如何配置. 2016-1-23 深圳 南山平山村 曾剑锋 一. ...

  6. Android自定义的webView——可实现的网页文本的复制

    package com.example.customlinearlayout.view; import android.app.ProgressDialog; import android.conte ...

  7. Linux 7 中Yum 配置 说明

    在之前的Blog中写了Linux Yum 的配置方法,参考: Linux 平台下 YUM 源配置 手册 http://www.cndba.cn/account/article/details/154 ...

  8. Windows 编译器选项 Runtime Library

    https://msdn.microsoft.com/library/2kzt1wy3%28v=vs.100%29.aspx http://blog.csdn.net/ybxuwei/article/ ...

  9. .Net刷新页面的小结

    现在给大家讲讲在.Net中书信页面的几种方式: 第一: private void Button1_Click( object sender, System.EventArgs e ) { Respon ...

  10. 关于join算法的四篇文章

    MySQL Join算法与调优白皮书(一) MySQL Join算法与调优白皮书(二) MySQL Join算法与调优白皮书(三) MySQL Join算法与调优白皮书(四) MariaDB Join ...