李友


私信TA

用户名:iui

访问量:3342

签 名:

等  级
排  名 351
经  验 5127
参赛次数 0
文章发表 16
年  龄 0
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 人数
		int max = sc.nextInt(); // 最大值
		int num = sc.nextInt(); // 个数
		long sum = 1, t = 1, a = 1;
		for (int i = 1; i < num; ++i) {
			//前n项和为(首项+末项)*n/2
			t = (((a + a + n - 1) * n / 2) + t) % max;
			sum += t;
			//一轮下来排第几名
			a += n;
		}
		System.out.println(sum);
	}

}


 

0.0分

4 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区