Consecutive Factors (20)
来源:互联网 发布:淘宝差评会被寄 编辑:程序博客网 时间:2024/06/04 01:29
题目描述
Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.
输入描述:
Each input file contains one test case, which gives the integer N (1<n<231).
输出描述:
For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format "factor[1]*factor[2]*...*factor[k]", where the factors are listed in increasing order, and 1 is NOT included.
输入例子:
630
输出例子:
35*6*7我的代码:
#include<stdio.h>int prime(int n){int i;if(n<2) return 0;else if(n==2) return 1;else{for(i=2;i*i<=n;i++){if(n%i==0) return 0;}return 1;}}int main(){int n,a[1001],i,j,k=0,max=0,t;scanf("%d",&n);if(prime(n)==1) printf("%d\n%d\n",1,n);else{for(i=2;i*i<=n;i++){if(n%i==0) a[k++]=i;}for(i=0;i<k;i++){int m=n,cnt=0;for(j=a[i];j>=2;j--){if(m%j==0) cnt++,m=m/j;else break;}if(cnt>max) max=cnt,t=i;}printf("%d\n%d",max,a[t-max+1]);for(i=t-max+2;i<=t;i++) printf("*%d",a[i]);}return 0;}
阅读全文
0 0
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- PAT-Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- PAT Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- 1096. Consecutive Factors (20)
- ApplicationContext中Bean的生命周期
- diffie-hellman-group1-sha1
- 同一文件夹下.py调用另一个.py文件的函数
- Spring
- EditView 使其开始不获得焦点
- Consecutive Factors (20)
- html5中的canvas属性一些简单例子
- charles 抓包外网程序
- 【训练】2017-11-6早
- 机器学习_参数估计(已知解析式求参数)
- IOS safari 浏览器 时间乱码(ios时间显示NaN) 问题解决
- RPC原理
- MySql 安装
- Android Framework下手机状态栏一体化和一体化后颜色存在的问题