vijos P1033 整数分解(版本2)
来源:互联网 发布:拼多多提现网络繁忙 编辑:程序博客网 时间:2024/05/22 20:07
~~~题目链接~~~
思路:
3 = 1+24 = 2+25 = 2+36 = 3+37 = 2+2+38 = 2+3+39 = 3+3+310 = 2+2+3+3..........
通过分解发现把一个数分解成尽可能多的2与3就为最大值。
code:
#include <stdio.h>#include <string.h>#include <math.h>using namespace std;struct node{ int num[1002]; int cnt;}p;void multipy(int c, int pow, int n){ int i = 0, cnt = p.cnt; if(c >= n) return ; for(i = 0; i<=cnt; i++) p.num[i] *= pow; for(i = 0; i<cnt; i++) if(p.num[i]>9) p.num[i+1] += p.num[i]/10, p.num[i] = p.num[i]%10; if(p.num[i]>9) p.num[i+1] += p.num[i]/10, p.num[i] = p.num[i]%10, cnt = i+1; p.cnt = cnt; multipy(c+1, pow, n);}int main(){ //freopen("input.txt", "r", stdin); int i = 0, j = 0, n = 0, x = 0, y = 0; scanf("%d", &n); if(n == 1) printf("1\n"); else { x = n/3; y = (n%3)/2; if(n%3%2) x--, y += 2; p.cnt = 0; memset(p.num, 0, sizeof(p.num)); p.num[0] = 3; multipy(0, 3, x-1); if(x <= 0) p.num[0] = 2, y--; multipy(0, 2, y); for(i = p.cnt; i>-1; i--) printf("%d", p.num[i]); printf("\n"); } //printf("%.0lf", pow(3, x)*pow(2, y)); return 0;}
- vijos P1033 整数分解(版本2)
- 数和分解,乘积最大-vijos整数分解(版本2)
- VIJOS-P1033
- 整数分解(版本2)
- Vijos P1033 家族
- vijos1033 整数分解(版本2)
- 【vijos1033】【数值/数论】【高精度乘法】整数分解(版本2)
- 整数分解
- 分解整数
- 整数分解
- 整数分解
- Vijos P1786 质因数分解【质因数分解】
- Vijos 1786题:质因数分解
- 整数分解为2的幂
- 1383 整数分解为2的幂
- 整数的2的幂分解
- 整数分解为2的幂
- 整数分解算法
- 位域操作符
- 使用非2次方幂的图像纹理的问题
- osgEarth linux 编译
- IOS的app程序中的文件目录的功能和使用详细说明
- josephus问题用面向对象的方法来实现
- vijos P1033 整数分解(版本2)
- Entity Framewrok实体框架 第一天
- jsp声明
- 秒杀多线程第4篇 一个经典的多线程同步问题
- computer science 经典书籍及书评
- 常用的配置文件-SSH-2
- 微软WinRT开发人员的一些解答
- non-power-of-two (NPOT) textures
- mysql读事务的隔离级别