hdu4432 Sum of divisors(数论)
Sum of divisors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2063 Accepted Submission(s): 718
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.
n and m.(n, m would be given in 10-based)
1≤n≤10
9
2≤m≤16
There are less then 10 test cases.
30 5
112
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 <stdio.h>
#include <math.h>
using namespace std;
int vet[10000];
int main()
{
int n,m,all,sum,s,ii,i,t;
char str[17]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E'};
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==1)
{
printf("1\n");
continue;
}
all=n;sum=0;
for(i=2;i<all;i++)
{
if(n%i==0)
{
all=n/i;//注意这一步优化,最关键的一步,如果i是n的因数,那么我们直接把i和n/i一起算了,i的上界变成了n/i-1
// printf("%d %d",i,n/i);
s=0;
ii=i;
while(ii)
{
t=ii%m;
s+=t*t;
ii=ii/m;
}
ii=n/i;
while(ii)
{
t=ii%m;
s+=t*t;
ii=ii/m;
}
sum+=s;
}
}
s=0;
ii=n;
while(ii)
{
t=ii%m;
s+=t*t;
ii=ii/m;
}
sum+=s;
sum++;
t=0;
while(sum)
{
vet[t++]=sum%m;
sum=sum/m;
}
for(i=t-1;i>=0;i--)
{
printf("%c",str[vet[i]]);
} printf("\n"); }
return 0;
}
hdu4432 Sum of divisors(数论)的更多相关文章
- HDU4432 Sum of Divisors
涉及知识点: 1. 进制转换. 2. 找因子时注意可以降低复杂度. Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- Project Euler 501 Eight Divisors (数论)
题目链接: https://projecteuler.net/problem=501 题意: \(f(n)\) be the count of numbers not exceeding \(n\) ...
- codeforces 616E Sum of Remainders (数论,找规律)
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- zoj 2286 Sum of Divisors
// f(n)表示 n的约数和 不包括自己// 给你一个m 求1 到 100万里面 f(n)<=m 的个数// 那么首先要用筛选求出所有出 f(n)// 然后就好办了 // 写好后 看见别人好快 ...
- hdu 4432 Sum of divisors(十进制转其他进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432 代码: #include<cstdio> #include<cstring&g ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
- GCD SUM 强大的数论,容斥定理
GCD SUM Time Limit: 8000/4000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatu ...
- ZOJ2286 Sum of Divisors 筛选式打表
我想我是和Segmentation Fault有仇,我一直以为是空间开大的问题,然后一直减少空间,还是SF,谁让n没有给范围了,qwq. 教训:以后注意输入范围和开的空间大小. #include< ...
随机推荐
- [记录 ]升级IOS 9 和 XCode 7 引起的问题
问题一: 升级xcode 7最低的系统配置要求 升级了ios9 后使用 xcode 6.1 已经不能用了,必须升级 xcode 7才行,原先的系统是OSX 10.10.1 版本.而xcode 7.0 ...
- OI中神奇的神器fillchar
传说,Pascal中有一个函数——fillchar.这是高手们装*用的利器,也是大家的神器(大家好才是真的好). 神器介绍: 百度百科说:“Fillchar是Turbo/Borland Pascal的 ...
- java中内部类的定义与访问规则
java内部类总结 简单来说,内部类就是在我们所熟悉的类中的里面再定义一个类 为什么需要内部类? 当我们描述事物时,事物之中还有事物,我们就用内部类描述事物 因为内部事物在使用外部事物的内容 我举一个 ...
- hdu 1250 Hat's Fibonacci(高精度数)
// 继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two membe ...
- Skia
1 What is SKIA. Skia is an open source 2D graphics library which provides common APIs that work acro ...
- C#生成二维码名片
摘自<31天学会CRM项目开发<C#编程入门级项目实战>> 本例将使用ThoughtWorks.QRCode类库生成二维码名片.正式编码前,先了解一下什么是vCard?它是一种 ...
- 我爱工程化 之 gulp 使用(二)
上一篇 介绍了gulp的安装.环境等配置.基本使用,那么现在,我们快走进 速8,深入了解吧...... 一.各种安装.环境配置.插件安装(参考上一篇文章) 二.项目基本目录结构 三.编写 gulpf ...
- 细说 ASP.NET Cache 及其高级用法
许多做过程序性能优化的人,或者关注过程程序性能的人,应该都使用过各类缓存技术. 而我今天所说的Cache是专指ASP.NET的Cache,我们可以使用HttpRuntime.Cache访问到的那个Ca ...
- CSS3制作hover下划线动画
1.前几天看到Hexo的next主题标题hover效果很炫,自己尝试写了一个,另一个是next的实现,照例先上图 2.实现小黑科技 <div> <a href="javas ...
- javascript进阶——分离式DOM脚本编程
编写分离式(unobstrusive)代码意味着对HTML内容的完全分离:数据来自服务器端,javascript代码用来动态化和交互.这种分离的好处是在不同浏览器之间使用是可以完全降级或升级运行,对于 ...