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< ...
随机推荐
- JDOM方法实现对XML文件的解析
首先要下载JDOM.jar包,下载地址:http://download.csdn.net/detail/ww6055/8880371 下载到JDOM.jar包之后导入到工程中去. 实例程序: book ...
- 【html】【8】div布局[子div在父div居底]
从今天起 开始细话div布局 思路及要点: 父div的位置设置成相对的,即“position: relative;”. 而子div的位置设置成绝对的,并且下边缘设为0,即“position: ab ...
- centos 7下配置mysql+php(ThinkPHP)+nginx
最近在Linux平台上配置服务器部署网站(说多了都是泪!),记个笔记! 一.首先是在centos下安装mysql (参考博客) mysql yum库提供了一个简单的和方便的方法来安装和更新MySQL相 ...
- 实现一个div在浏览器水平居中
第一种方法: div { margin: 0 auto; width: 960px; } 第二种方法(兼容IE): body { text-align: center; } div { margin: ...
- php用正则表达式获取网站的标题内容
已知网站的网址,用php获取网站的内容. 编写正则表达式. 用preg_match_all函数获取标题内容. $url='http://www.m-ivi.com'; $content=file_ge ...
- mysql中的load命令使用方法
使用mysql 中的load 命令,可以将txt 文件中的内容加载到数据库表中 使用mysql 中的load 命令,讲txt 文件中的内容加载到数据库表中,例如,创建table,名称是user,一个字 ...
- Django基本操作命令
1.新建一个django项目 django-admin.py startproject project-name 2.新建一个app python manage.py startapp app-nam ...
- mysql 远程连接 2003 Can't connect to MySQL server (10060)
mysql server 端的端口被防火墙挡出,没有开放
- 【BZOJ】1012: [JSOI2008]最大数maxnumber 树状数组求区间最值
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1012 题意:维护一个数列,开始时没有数值,之后会有两种操作, Q L :查询数列末 ...
- Centos 6.2 32位机器安装新的JDK和Weblogic
一.首先卸载自带的JDK 1.查看自带的java版本. root@admin]#java -version java version "1.6.0" OpenJDK Runtime ...