def is_Power_of_four(n):
while n and not (n & 0b11):
n >>=
return (n == ) print(is_Power_of_four())
print(is_Power_of_four())
print(is_Power_of_four())
print(is_Power_of_four())
相关文章
- #include <> typedef struct Node { int index; struct Node *next; }JosephuNode; int Josephu(int n, int m) { int i, j; JosephuNode *head, *tail; head = tail = (JosephuNode *)malloc(sizeof(JosephuNode)); for (i = 1; i < n; ++i) { tail->index = i; tail->next = (JosephuNode *)malloc(sizeof(JosephuNode)); tail = tail->next; } tail->index = i; tail->next = head; for (i = 1; tail != head; ++i) { for (j = 1; j < m; ++j) { tail = head; head = head->next; } tail->next = head->next; printf("第%4d个出局的人是:%4d号\n", i, head->index); free(head); head = tail->next; } i = head->index; free(head); return i; } int main { int n, m; scanf("%d%d", &n, &m); printf("最后胜利的是%d号!\n", Josephu(n, m)); system("pause"); return 0; }">设编号为1,2,… n的n个人围坐一圈,约定编号为k(1数组实现: #include <> #include <> int Josephu(int n, int m) { int flag, i, j = 0; int *arr = (int *)malloc(n * sizeof(int)); for (i = 0; i < n; ++i) arr[i] = 1; for (i = 1; i < n; ++i) { flag = 0; while (flag < m) { if (j == n) j = 0; if (arr[j]) ++flag; ++j; } arr[j - 1] = 0; printf("第%4d个出局的人是:%4d号\n", i, j); } free(arr); return j; } int main { int n, m; scanf("%d%d", &n, &m); printf("最后胜利的是%d号!\n", Josephu(n, m)); system("pause"); return 0; } 链表实现: #include <> #include <> typedef struct Node { int index; struct Node *next; }JosephuNode; int Josephu(int n, int m) { int i, j; JosephuNode *head, *tail; head = tail = (JosephuNode *)malloc(sizeof(JosephuNode)); for (i = 1; i < n; ++i) { tail->index = i; tail->next = (JosephuNode *)malloc(sizeof(JosephuNode)); tail = tail->next; } tail->index = i; tail->next = head; for (i = 1; tail != head; ++i) { for (j = 1; j < m; ++j) { tail = head; head = head->next; } tail->next = head->next; printf("第%4d个出局的人是:%4d号\n", i, head->index); free(head); head = tail->next; } i = head->index; free(head); return i; } int main { int n, m; scanf("%d%d", &n, &m); printf("最后胜利的是%d号!\n", Josephu(n, m)); system("pause"); return 0; }
- 给一个正整数 n, 找到若干个完全平方数(比如1, 4, 9, ... )使得他们的和等于 n。你需要让平方数的个数最少。
- 牛牛定义排序子序列为一个数组中一段连续的子序列,并且这段子序列是非递增或者非递减排序的。牛牛有 一个长度为n的整数数组A,他现在有一个任务是把数组A分为若干段排序子序列,牛牛想知道他最少可以把这个 数
- 编写一个算法来判断一个数是不是“快乐数”。 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和, 然后重复这个过程直 到这个数变为 1,也可能是无限循环但始终变不到 1
- 快乐数-判断一个数字是否是快乐数
- python输入包含多组测试数据_输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6...
- java中n次方怎么表示_java如何计算一个数的n次方
- 输入一个数,判断是否是偶数!
- 如何快速的判断一个数是否是偶数-Java实现
- 从键盘上输入3个正整数,判断这3个正整数是否可以构成一个三角形,进一步判断是等边(输出1)、等腰(输出2) 回文是指正读和反读都一样的数或字符,键盘上读取一个包含5位数字的长整数,并判断它是否是回文