迅雷9.12 笔试
第一题,有正数A,和负数B,选m个A,n个B排成一排,使:m+n = 17 ,且任意相邻7个数和小于0,问这17个数的最大和是多少?
思路:找出7个数中至少需要几个B,然后按,A...A B...B A..A B...B A...A B...B 排列,取前17个,这样保证后三个尽可能使正数A。最后只过了88%,不知道漏掉了什么情况。【求大佬指点一下】
第二题:有 a a + bb = c*c ,且,a、b、c互质,求满足 0<a<b<c<=N的(a,b,c)有多少组
思路:a = jj - ii; b = 2ji; c = jj - ii; 则只有 j 和 i 满足互质且一个为奇数一个为偶数,则可得到一组满足题意的 a,b,c
//第一题 package com.zhudky; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); int AOfSeven = 7; while(AOfSeven>0){ int temp = A*AOfSeven + B*(7-AOfSeven); if(temp<0){ break; } AOfSeven--; } int numOfA = 2*AOfSeven ; int numOfB = 2*(7-AOfSeven); int num = numOfA + numOfB; while(num<=17){ int temp = Math.min(AOfSeven,17-num); if(temp>0){ num += temp; numOfA+= temp; } else{ break; } temp = Math.min(7-AOfSeven,17-num); if(temp>0){ num += temp; numOfB += temp; } else{ break; } } int re = A*numOfA + B*numOfB; System.out.println(re); } }
//第二题 package com.zhudky; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); int m = (int)Math.floor(Math.sqrt(N)); int re =0; for (int i = 1; i < m+1; i++) { for (int j = i+1; j < m+1; j+=2) { //int a = j*j - i*i; //int b = 2*j*i; long c = j*j + i*i; if(c<=N && gcd(j,i)==1 ){ re++; } else if(c>N){ break; } } } System.out.println(re); } private static int gcd(int x,int y){ return (x%y != 0) ? gcd(y,x%y):y; } }#迅雷##笔试题目##题解#