hdu4432 - Sum of divisors
来源:互联网 发布:sql删除1000行数据 编辑:程序博客网 时间:2024/05/16 16:04
http://acm.hdu.edu.cn/showproblem.php?pid=4432
下面一种是直接模拟,一种就是进行优化了;
理解题意即可:
给你两个数:n 和m
先将n转换成m进制数,然后将各个位置上的数值平方求和,最后在按照m进制输出即可
#include "stdio.h"#include "string.h"#include "stdlib.h"#include "math.h"#include "algorithm"#include "iostream"using namespace std;int num[ 105 ] ; int main(){int n , m , i ,s;while( ~scanf( "%d%d" ,&n ,&m ) ){s = 0 ;for( i = 1 ; i <= sqrt( n ) ; i++ ){if( n % i == 0 ){int k = i ;while( k ){s += ( k % m ) * ( k % m ) ;k /= m ;}if( i * i != n ){int k = n / i ;while( k ){s += ( k % m ) * ( k % m ) ;k /= m ;}}}}num[ 0 ] = 0 ;int t = 0 ;while( s ){num[ t++ ] = s % m ;s /= m ;}t-- ;for( i = t ; i >= 0 ; i-- ){if( num[ i ] > 9 ){printf( "%c" , num[ i ] - 10 + 'A' ) ;}elseprintf( "%d" , num[ i ] ) ;}printf( "\n" );}return 0;}
#include "stdio.h"#include "stdlib.h"#include "string.h"#include "math.h"#include "iostream"#define LL long longusing namespace std;int m, buf2;LL buf[999999];LL cal(LL temp){LL buf2 = 0, res = 0;while (temp){buf2 = temp % m;temp /= m;res += (buf2 * buf2);}return res;}int main(){LL n, res;while (~scanf("%lld%d", &n, &m)){res = 0;memset(buf, 0, sizeof(buf));int i = 1;for (int j = 1; j <= sqrt(n); j++){if (!(n % j)){buf[i] = j;i += 1;res += cal(j);if (j != n / j){buf[i] = n / j;i += 1;res += cal(n / j);}}}i = 1;while (res){buf[i++] = res % m;res /= m;}for (int j = i - 1; j >= 1; j--){if (buf[j] <= 9)printf ("%d", buf[j]);elseprintf ("%c", buf[j] + 'A' - 10);}printf ("\n");}return 0;}
- hdu4432 Sum of divisors
- hdu4432 - Sum of divisors
- hdu4432 Sum of divisors
- [hdu4432]Sum of divisors
- [HDU4432][TJ02B]Sum of divisors
- hdu4432 Sum of divisors(数论)
- Sum of divisors
- Sum of divisors
- zoj 2286 Sum of Divisors
- HDU 4432 Sum of divisors
- HDU:4432 Sum of divisors
- hdu 4432 Sum of divisors
- HDOJ4432 Sum of divisors(暴力)
- hdu 4432 Sum of divisors
- HDU 4432 Sum of divisors
- HDU 4432(Sum of divisors)
- ZOJ 2286 Sum of Divisors(打表)
- hdu 4432 Sum of divisors(暴力)
- Position定位:relative | absolute
- ADO.NET数据库访问
- VC执行存储过程
- Sql Server数据库的存储过程
- Effective C++读书笔记 第五部分 实现(Implementations)
- hdu4432 - Sum of divisors
- JAVA-第一天
- SQLite3 API编程手册
- C编程第6篇---复合数据类型
- C语言之动态存储分配函数
- QML Flickable使用
- 单件模式【C++】【转载】
- MediaRecorder类介绍 方法已经翻译成中文了
- unix shell中(),[]和[[]]的区别