PAT 甲级 1096 Consecutive Factors

2024-06-19 16:32

本文主要是介绍PAT 甲级 1096 Consecutive Factors,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

PAT 甲级 1096 Consecutive Factors

#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef LOCALfreopen("input.txt", "r", stdin);
#endifint num, max_len = -1, now_len = 0, beg = 0, now_beg;cin >> num;for (int i = 2; i <= ceil(sqrt(num)); ++i) {if (num % i == 0) {int j   = i;now_len = 0, now_beg = j;// 防止溢出long long tmp = j;while (num % tmp == 0) {++j, tmp *= j;}now_len = j - now_beg;if (now_len > max_len) {max_len = now_len, beg = now_beg;}}}if (max_len == -1) {// 小于等于ceil(sqrt(num))的没有num的因子,说明num是素数printf("1\n%d", num);}else {cout << max_len << endl;for (int i = 0; i < max_len; ++i) {if (i != 0) cout << "*";cout << i + beg;}}
}

这篇关于PAT 甲级 1096 Consecutive Factors的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1075555

相关文章

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

PAT甲级-1044 Shopping in Mars

题目   题目大意 一串项链上有n个钻石,输入给出每个钻石的价格。用m元买一个连续的项链子串(子串长度可为1),如果不能恰好花掉m元,就要找到最小的大于m的子串,如果有重复就输出多个,按递增顺序输出子串的前端和后端索引。 原来的思路 取连续的子串使和恰等于m,没有恰等于就找最小的大于。可以将子串依次累加,使得每个位置都是起始位置到该位置的序列和,整个数组显递增顺序,就可以用右边减左边

PAT (Advanced Level) Practice——1011,1012

1011:  链接: 1011 World Cup Betting - PAT (Advanced Level) Practice (pintia.cn) 题意及解题思路: 简单来说就是给你3行数字,每一行都是按照W,T,L的顺序给出相应的赔率。我们需要找到每一行的W,T,L当中最大的一个数,累乘的结果再乘以0.65,按照例子写出表达式即可。 同时还需要记录每一次选择的是W,T还是L

[LeetCode] 485. Max Consecutive Ones

题: 题目 Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consec

[LeetCode] 128. Longest Consecutive Sequence

题:https://leetcode.com/problems/longest-consecutive-sequence/description/ 题目 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should

Replace All ?‘s to Avoid Consecutive Repeating Characters

Given a string s containing only lower case English letters and the '?' character, convert all the '?' characters into lower case letters such that the final string does not contain any consecutive re

PAT (Advanced Level) Practice

1001:  题目大意: 计算 a+b 的结果,并以标准格式输出——即每三个数字一组,组之间用逗号分隔(如果数字少于四位,则不需要逗号分隔)  解析: 我们知道相加右正有负,对于样例来说 Sample Input: -1000000 9 Sample Output: -999,991 如果是从左往右,算上负号的话输出应该是-99,999,1 从右往左:-,999,991离正确

1050 String Subtraction——PAT甲级

Given two strings S1​ and S2​, S=S1​−S2​ is defined to be the remaining string after taking all the characters in S2​ from S1​. Your task is simply to calculate S1​−S2​ for any given strings. However,

1105 链表合并——PAT乙级

给定两个单链表 L1​=a1​→a2​→⋯→an−1​→an​ 和 L2​=b1​→b2​→⋯→bm−1​→bm​。如果 n≥2m,你的任务是将比较短的那个链表逆序,然后将之并入比较长的那个链表,得到一个形如 a1​→a2​→bm​→a3​→a4​→bm−1​⋯ 的结果。例如给定两个链表分别为 6→7 和 1→2→3→4→5,你应该输出 1→2→7→3→4→6→5。 输入格式: 输入首先在第一

1110 区块反转——PAT乙级

给定一个单链表 L,我们将每 K 个结点看成一个区块(链表最后若不足 K 个结点,也看成一个区块),请编写程序将 L 中所有区块的链接反转。例如:给定 L 为 1→2→3→4→5→6→7→8,K 为 3,则输出应该为 7→8→4→5→6→1→2→3。 输入格式: 每个输入包含 1 个测试用例。每个测试用例第 1 行给出第 1 个结点的地址、结点总个数正整数 N (≤105)、以及正整数 K (