File tree Expand file tree Collapse file tree
P1075 [NOIP 2012 普及组] 质因数分解 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments