HDU 4432 Sum of divisors (水题,进制转换)
2016-08-11 21:35
302 查看
题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和。
析:按它的要求做就好,注意的是,是因数,不可能有重复的。。。比如4的因数只有一个2,还有就是输出10进制以上的,要用AB。。
但我用的是ab。。又没读好题。。。。活该WA了好几次。
代码如下:
析:按它的要求做就好,注意的是,是因数,不可能有重复的。。。比如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 (进制模拟)
- hdu 4432 Sum of divisors
- HDU 4432 Sum of divisors 2012 Asia Tianjin Regional Contest
- HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
- HDU 4432 Sum of divisors (进制模拟)
- HDU 4432 Sum of divisors 质因数分解
- HDU 4432 Sum of divisors
- B - Sum of divisors HDU - 4432
- HDU 4432 Sum of divisors
- HDU 4432 Sum of divisors (进制模拟)
- HDU-4432-Sum of divisors ( 2012 Asia Tianjin Regional Contest )
- HDU 4432 Sum of divisors (进制转换模板)
- HDU—— 4432 Sum of divisors
- HDU 4432 因子之和以及进制转换问题
- hdu 4432 Sum of divisors(十进制转其他进制)
- HDU 4432 求因子+进制转换
- HDU:4432 Sum of divisors
- hdoj 4432 Sum of divisors
- HUD 4432 Sum of divisors 天津现场赛B题
- hdu 4432 Sum of divisors