没心情写数学题啦啊 好难啊 #include<bits/stdc++.h> using namespace std; set<int> s; set<int>::iterator it; int main () { s.clear(); ;i*i<=1e9;i++) s.insert(i*i); int n; scanf("%d",&n); ; ;i*i<=n/;i++) { int t = n-i*i; if(s.find(…
Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False Accepted 38,694 Submissions 117,992 …
题目:在一个数组中,除了两个数外,其余数都是两两成对出现,找出这两个数,要求时间复杂度O(n),空间复杂度O(1) 分析:这道题考察位操作:异或(^),按位与(&),移位操作(>>, <<)等,Java代码及注释如下: public static int[] findTwoSingleNum(int[] num) { int[] twoNums = new int[2]; int result = 0; for (int i = 0; i < num.length;…
一个简单的小算法来获取两个数的最大公约数, public class Test { public static void main(String[] args) { long result = gcd(15, 3); System.out.println(result); } public static long gcd(long m, long n) { while (n != 0) { long rem = m % n; m = n; n = rem; } return m; } }…