首页 > 学院 > 开发设计 > 正文

1096. Consecutive Factors (20)

2019-11-11 01:49:54
字体:
来源:转载
供稿:网友

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.

Input Specification:

Each input file contains one test case, which gives the integer N (1

#include<cstdio>#include<cmath>typedef long long ll;int main(){ ll n; scanf("%lld",&n); ll a=(ll)sqrt(n); int ansI=0,ansLen=0; for(int i=2;i<=a;i++){ int j=i; ll temp=1; while(1){ temp*=j; if(n%temp!=0) break; if(ansLen<j-i+1){ ansI=i; ansLen=j-i+1; } j++; } } if(ansLen==0){ PRintf("1/n%lld/n",n); }else{ printf("%lld/n",ansLen); for(int i=0;i<ansLen;i++){ if(i<ansLen-1){ printf("%lld*",ansI+i); }else{ printf("%lld/n",ansI+i); } } } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表