Untitled
unknown
plain_text
10 months ago
1.9 kB
5
Indexable
//1
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n;
cin >> n;
int tong = 0;
int dem = 0;
for (int i = 1; i <= sqrt(n);i++)
{
if(n % i == 0){
dem++;
tong += i;
if (n / i != i){
dem++;
tong += n / i;
}
}
}
cout << n << " co " << dem << " uoc duong" << endl;
cout << "Tong cua chung la: " << tong << endl;
}
//2
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
while (n > 1)
{
if (n % 2 == 0){
n /= 2 ;
}
else{
n = n * 3 + 1 ;
}
cout << n << " ";
}
}
//3
#include<iostream>
using namespace std;
int main()
{
int a , b;
cin >> a >> b;
int tong = 0;
for (int i = a; i <= b ; i++){
if (i % 3 != 0){
cout << i << " ";
}
else {
continue;
}
tong += i;
}
cout << "\n" << tong << endl;
}
//4
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n ; i++){
for (int j = 1; j <= 2 * n - 1; j++){
if (j <= n - i || j >= n + i){
cout << " ";
}
else {
cout << "x";
}
}
cout << endl;
}
}
//5
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n;
int tmp;
cin >> n;
int dem = 0;
for (int i = 1; i <= n ; i++){
cin >> tmp;
for (int k = 1;k <= sqrt(tmp); k++){
if (tmp % k == 0){
dem++;
if ( tmp / k != k){
dem++;
}
}
}
(dem == 3)? cout << "YES\n" : cout << "NO\n";
}
}
Editor is loading...
Leave a Comment