1096. Consecutive Factors (20)
时间限制400 ms
内存限制65536 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
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<N<231).
Output Specification:
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.
Sample Input:630Sample Output:3 5*6*7输入N;(找到一个数是N的因数,且由最多的连续的数乘起来的【这些数不包括1】;如果有多个,那么输出第一个比较小的);输出格式这个数有几个连续的数乘起来这些数是哪些(从小到大),中间间隔*例如:N=得到12N=1222*3N=515
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月19日 18:07 | 答案正确 | 20 | 1096 | C++ (g++ 4.7.2) | 1 | 384 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 308 | 10/10 |
1 | 答案正确 | 1 | 384 | 2/2 |
2 | 答案正确 | 1 | 308 | 2/2 |
3 | 答案正确 | 1 | 384 | 2/2 |
4 | 答案正确 | 1 | 180 | 2/2 |
5 | 答案正确 | 1 | 308 | 1/1 |
6 | 答案正确 | 1 | 180 | 1/1 |
#include<iostream> #include<vector> #include<math.h> using namespace std; int main() { int N,index,maxlen,starindex,tempstar,endindex; int more; cin >> N; vector<int>factor; tempstar = sqrt(N) + 1; for (index = 2; index <tempstar; index++) if (N%index == 0)factor.push_back(index); factor.push_back(N);/*获取除了1以外的因数,包括它本身*/ endindex= factor.size(); maxlen = 1; starindex = 0;/*假如只有一个非1的因数,那么它本身,且个数为1*/ tempstar = 0; for (tempstar = 0; tempstar< endindex; tempstar++) { more = factor[tempstar]; for (index= tempstar + 1; index< endindex&&N%(more*factor[index]) ==0&&factor[index] == factor[index- 1] + 1; index++)/*在这些因数中找连续的且乘积也是N的因数*/ more*=factor[index]; if (maxlen < index- tempstar)/*判断连续的是否更长,是替换*/ { maxlen = index - tempstar; starindex = tempstar; } } cout << maxlen << endl; cout << factor[starindex++]; maxlen = starindex + maxlen - 2; for (; starindex <= maxlen; starindex++) cout << "*" << factor[starindex]; cout << endl; system("pause"); return 0; }