📑前言
本文主要是【算法】——蓝桥杯练习题(五)的文章,如果有什么需要改进的地方还请大佬指出⛺️
🎬作者简介:大家好,我是听风与他🥇
☁️博客首页:CSDN主页听风与他
🌄每日一句:狠狠沉淀,顶峰相见文章来源:https://www.toymoban.com/news/detail-789634.html
2080.求和
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
StreamTokenizer sc = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
sc.nextToken();
int n = (int)sc.nval;
int a[] = new int[n];
long sum[] = new long[n+1];
for(int i=0;i<n;i++) {
sc.nextToken();
a[i] = (int)sc.nval;
}
sum[0]=a[0];
for(int i=1;i<n;i++) {
sum[i]=sum[i-1]+a[i];
}
long res = 0;
for(int i=0;i<n;i++) {
res+=a[i]*(sum[n-1]-sum[i]);
}
System.out.println(res);
}
}
2145.求阶乘
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long l = 1;
long r = (long)9e18;
while(l<r) {
long mid = (r-l)/2+l;
if(f(mid)>=n) {
r = mid;
}else {
l = mid+1;
}
}
if(f(l)==n) {
System.out.println(l);
}else {
System.out.println(-1);
}
}
public static long f(Long n) {
long ans = 0;
while(n>0) {
ans+=n/5;
n/=5;
}
return ans;
}
}
2140.星期计算
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = f(20, 22);
System.out.println((a+6)%7==0?7:(a+6)%7);
}
public static int f(int a,int b) {
int ans=1,t=a;
for(int i=0;i<b;i++) {
ans=a%7;
a=ans*t;
}
return ans;
}
}
📑文章末尾
文章来源地址https://www.toymoban.com/news/detail-789634.html
到了这里,关于蓝桥杯练习题(五)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!