Skip to content

Commit dbeab99

Browse files
committed
2 parents 702b983 + 70444e8 commit dbeab99

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

  • luogu/ProblemSet
    • P1075 [NOIP 2012 普及组] 质因数分解
    • P5725 【深基4.习8】求三角形
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <algorithm>
2+
#include <cmath>
3+
#include <cstdio>
4+
#include <cstdlib>
5+
#include <cstring>
6+
#include <iostream>
7+
#include <string>
8+
#include <vector>
9+
typedef long long ll;
10+
using namespace std;
11+
12+
int main() {
13+
ios::sync_with_stdio(false),cin.tie(0);
14+
int n;
15+
cin >> n;
16+
for(int i = 2;i<=n;++i)
17+
{
18+
if(n%i == 0)
19+
{
20+
cout << n/i << endl;
21+
return 0;
22+
}
23+
}
24+
25+
return 0;
26+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <iomanip> // 用于 setw 和 setfill
3+
using namespace std;
4+
5+
int main() {
6+
ios::sync_with_stdio(false);
7+
cin.tie(0);
8+
9+
int n;
10+
if (!(cin >> n)) return 0;
11+
12+
// 第一部分:打印 n*n 矩阵
13+
for (int i = 0; i < n; ++i) { //
14+
for (int j = 1; j <= n; ++j) { //
15+
int num = i * n + j;
16+
// 使用 setw(2) 占据2个字符宽度, setfill('0') 没满的地方补0
17+
cout << setfill('0') << setw(2) << num;
18+
}
19+
cout << endl; // 一行打印完后再换行
20+
}
21+
22+
cout << endl; // 两个图形中间空一行
23+
24+
// 第二部分:打印三角形
25+
int cnt = 1;
26+
for (int i = 1; i <= n; i++) {
27+
// 打印空格
28+
for (int j = 1; j <= n - i; j++) {
29+
cout << " ";
30+
}
31+
32+
// 打印数字
33+
// 原逻辑: while(cnt <= i * (i + 1) / 2) 其实就是打印 i 个数字
34+
for (int k = 0; k < i; k++) {
35+
cout << setfill('0') << setw(2) << cnt;
36+
cnt++;
37+
}
38+
cout << endl;
39+
}
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)