PAT 天梯赛 L1-006. 连续因子 【循环】
2024-09-27 15:11:22
题目链接
https://www.patest.cn/contests/gplt/L1-006
思路
输出的连续因子 的乘积 也要是这个数的因子 就每个数先找它的单因子
然后每个单因子往上一个一个遍历 当 n % sum != 0 的时候 退出来 然后 比较 此答案 和 原答案的大小 如果 更大 就替换
要注意 质数的情况
AC代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int a[maxn];
int main()
{
int n;
cin >> n;
int i, j;
int vis = sqrt(n) + 1;
memset(a, 0, sizeof(a));
int temp;
for (i = 2, j = 0; i <= vis; i++)
{
if (n % i == 0)
a[j++] = i;
}
int len = j;
int max = 0, ans;
LL sum;
for (i = 0; i < len; i++)
{
sum = a[i];
vis = 1;
for (j = 1; ; j++)
{
sum *= (a[i] + j);
if (n % sum != 0)
break;
else
vis++;
}
if (vis > max)
{
max = vis;
ans = a[i];
}
}
if (len == 0)
{
cout << 1 << endl;
cout << n << endl;
}
else
{
printf("%d\n", max);
for (i = 0; i < max; i++)
{
if (i)
printf("*");
printf("%d", ans + i);
}
cout << endl;
}
}
最新文章
- 使用Nito.AsyncEx实现异步锁(转)
- ffmpeg-20160828-bin.7z
- java数据库连接池性能对比
- python requests库学习
- VS2010中无法嵌入互操作类型“......”,请改用适用的接口的解决方法
- Linq to Entities不识别方法
- 【JSP实例】指定用户计数器
- php多进程编程详解
- SQL SERVER 的前世今生--各版本功能对比
- 实验效果展示(会声会影+FSCapture)
- Android6.0 源码修改之 仿IOS添加全屏可拖拽浮窗返回按钮
- mysql case when 判断null
- 静态HTML总结
- win10下安装MinGW-w64 - for 32 and 64 bit Windows
- C#控制台程序输出彩色文字
- Python MySQLdb insert(插入) 封装
- Python入门之字符编码
- 【bzoj 4154】[Ipsc2015]Generating Synergy
- Spring整合MyBatis(四)MapperFactoryBean 的创建
- Kali渗透测试2-抓包/DNS工具