T1
public class T1 {
public static void main(String[] args) {
int cnt = 0;
for (int i= 1; i <= 2020; i ++) {
if (gcd(i,2020) == 1) {
cnt ++;
}
}
System.out.println(cnt);
}
private static int gcd(int i, int i1) {
return i1 != 0 ? gcd(i1,i % i1 ) : i;
}
}
T2
89
public class T2 {
public static void main(String[] args) {
int cnt = 0;
for (int i = 1; i <= 2021; i++) {
if (gcd(i,2021) > 1) cnt ++;
}
System.out.println(cnt);
}
static int gcd(int a, int b) {
return b!=0 ? gcd(b,a%b) : a;
}
}
T3
12
public class T3 {
public static void main(String[] args) {
int cnt = 0;
for (int i = 1; i <= 2020 / i; i++) {
if (2020 % i == 0) {
cnt++;
if (i != 2020 / i) cnt ++;
}
}
System.out.println(cnt);
}
}
T4
public class T4 {
public static void main(String[] args) {
int cnt = 0;
for (int i = 12; i <= 2020 ; i += 6) {
if (i % 4 == 0) cnt ++;
}
System.out.println(cnt);
}
}
T6
15488.0
- 1B (字节) = 8 bit(位)
- 1MB = 1024KB
- 1GB = 1024MB
- 1KB = 1024B
T7
67108864
System.out.println(256 * 1024 * 1024 / 4);
T8
**25600**
System.out.println(100 * 1024 / 4);
T9
14
public static void main(String[] args) {
int n = 1;
int cnt = 0;
while (n <= 10000) {
n <<= 1;
cnt ++;
}
System.out.println(cnt);
}
T10
左子树结点个数和右子树的结点个数之差最多为1,这句话的意思应该是这棵树是一颗完全二叉树。 根据完全二叉树的结点个数获得深度的公式是long2(N)+1。但这里说定义根节点的深度为0,所以我们不需要再加一,我得出来的答案是long(2021)~=10,最多是十层。
T11
二叉树节点关系公式 : n0 = n2 + 1
答案: 1001
度数为 2 的节点个数 1000 则: 度数为 0 的节点 1001 个 叶子节点即度数为0的节点。
T12
1010
与上题类似 : n0 = n2 + 1 , 转换 2019 = n0 + n2 + n1 ,最多 有多少个叶子节点,让 n1 空了就好了 转换为 2019 = n0 + n2 + 1 = 2n2 + 1; n2 = 1009 则 n0 有 1010 个。
T13
564
public static void main(String[] args) {
int cnt = 0;
for (int i = 1; i <= 2021; i++) {
int t = i;
while (t != 0) {
if (t % 10 == 2) {
cnt++;
break;
}
t /= 10;
}
}
System.out.println(cnt);
}