Pat(Advanced Level)Practice--1096(Consecutive Factors)
来源:互联网 发布:mac如何禁止开机启动 编辑:程序博客网 时间:2024/06/05 16:45
Pat1096代码
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:
35*6*7
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#define MAXN 50using namespace std;int main(int argc,char *argv[]){long long n;long long max=0;long long start=0;long long temp;long long j;scanf("%lld",&n);for(long long i=2;i*i<=n;i++){temp=n;for(j=i;j<=temp;j++){if(temp%j==0){temp/=j;}else{break;}}if(max<j-i){max=j-i;start=i;}}if(max!=0){printf("%lld\n",max);for(long long i=0;i<max;i++){printf("%lld",start);start++;if(i!=max-1){printf("*");}}printf("\n");}else{printf("1\n%lld\n",n);}return 0;}
奇怪!换成int类型,最后一个case超时!
- Pat(Advanced Level)Practice--1096(Consecutive Factors)
- PAT (Advanced Level) Practise 1096 Consecutive Factors (20)
- PAT (Advanced Level) Practise 1096 Consecutive Factors (20)
- 【PAT】【Advanced Level】1096. Consecutive Factors (20)
- Pat(Advanced Level)Practice--1059(Prime Factors)
- PAT (Advanced Level) 1096. Consecutive Factors (20) 连续质因数
- 1096. Consecutive Factors (20)——PAT (Advanced Level) Practise
- pat 1096 Consecutive Factors
- PAT (Advanced Level) Practice 1006
- 【PAT】【Advanced Level】1059. Prime Factors (25)
- PAT 1096-Consecutive Factors (20)
- Pat(Advanced Level)Practice--1025(PAT Ranking)
- Pat(Advanced Level)Practice--1075(PAT Judge)
- Pat(Advanced Level)Practice--1003(Emergency)
- Pat(Advanced Level)Practice--1004(Counting Leaves)
- Pat(Advanced Level)Practice--1008(Elevator)
- Pat(Advanced Level)Practice--1010(Radix)
- Pat(Advanced Level)Practice--1015(Reversible Primes)
- 第3章:缓冲I/O
- 手机本身可用存储空间和sdcard可用的存储空间
- 汇编学习笔记--查看CPU和内存
- java图片水印和图片缩放
- 重新教自己学算法之循环-递归(二)
- Pat(Advanced Level)Practice--1096(Consecutive Factors)
- spark1
- Python初探
- week13---5月26日(补充 DataTime)
- emberjs--环境搭建
- 动态规划之最长公共子序列(LCS)
- Socket 通信原理(Android客户端和服务器以TCP&&UDP方式互通)
- null-terminated char array
- 关于java浮点型的数据输出格式以及默认的基本数据类型转换