咖啡


私信TA

用户名:Tianxn

访问量:128081

签 名:

十年OI一场空,不开LL见祖宗。

等  级
排  名 8
经  验 26039
参赛次数 10
文章发表 197
年  龄 22
在职情况 学生
学  校 西安电子科技大学
专  业 软件工程

  自我简介:

解题思路:

为什莫这么做就不多说了,前面的大佬们已经解释过了;这里来说说具体是怎么的到东东每次所报的数(因为我觉得前面大佬说的不算清楚):

例如:n=3,k=13,T=3的时候对应的表如下(带颜色的是东东报的数)

0123456789
124711393117

东东所报的数用  t 表示

第1次:t1=1

第2次:t2=7 --> 7=((1+2+3)+1)%13 --> t2=((1+2+3)+t1)%k

第3次:t2=9 --> 9=((4+5+6)+7)%13 --> t3=((4+5+6)+t2)%k

把1+2+3和4+5+6拿出来说:

1+2+3就是首项a为1公差d为1的等差数的前n项和(n的值为3),首项为1,末项为1+(n-1)*d=1+n-1;

前n项和为(首项+末项)*n/2,即(1+1+n-1)*n/2 = 6;

4+5+6就是首项a为4公差d为1的等差数的前n项和(n的值为3),首项为4,末项为4+(n-1)*d=1+n-1;

前n项和为(首项+末项)*n/2,即(4+4+n-1)*n/2 = 15;


然后把上面的过程完善一下:

东东所报的数用  t 表示

第1次:t1=1

第2次:t2=7 --> 7=((1+2+3)+1)%13 --> t2=((1+2+3)+t1)%k --> t2=((1+1+n-1)*n/2+t1)%k;

第3次:t2=9 --> 9=((4+5+6)+7)%13 --> t3=((4+5+6)+t2)%k --> t2=((4+4+n-1)*n/2+t2)%k;

规律如上;如何衔接每次的结果:

            t就不说了看上面就很容易知道了;

            至于每次的首项和末项:定义一个变量 a 作为首项,初值为1,下次的首项就是a+n(即这个例子中的4),每次累加n就可以找到首项,末项用等差数列公式a1+(n-1)*d = a+n-1(d=1, n是通过键盘输入的);那么首项、末项都知道了,规律如上总结;可以解题了……



不懂留言,谢谢

注意事项:

参考代码:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
	int n, k, T;
	long long sum = 1, t=1, a=1;
	scanf("%d%d%d", &n, &k, &T);
	for(int i = 1; i < T; ++i)
	{
		t = (((a+a+n-1)*n/2)+t)%k;
		sum += t;
		a += n;
	}
	printf("%lld\n", sum);
	return 0;
}
 

0.0分

59 人评分

  评论区

大佬们哪里错了求告知
#include<stdio.h>
#include<math.h>
int main()
{
    int n,k,t,m=1,b,a=1;
    long long s=1;
    scanf("%d %d %d",&n,&k,&t);
    for(b=1;b<t;b++)
    {
        m=((n*(a+a+n-1))/2+m)%k;
        s=s+m;
        a=a+n;

    }
    printf("%lld",s);
    return 0;

}
2021-03-08 10:22:59
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()   
{
    long long int N,K,T,a=1,t;
    scanf("%lld %lld %lld",&N,&K,&T);
    long long int sum=0,i;
    for(i=0;i<T;++i){
    	t=(1+a*(a-1)/2)%K;
    	sum=sum+t;
    	a=a+N;
	}
	printf("%lld",sum);
	return 0;
} 
86分,不知道哪里有问题,有大佬知道吗?
2021-02-05 16:45:25
不知道我的错在哪里,有大佬帮忙看看嘛?

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	long long 	n,k,T;
	scanf("%lld",&n);
	scanf("%lld",&k);
	scanf("%lld",&T);
	int a[100]={0};
	int i;
	a[0]=1;
	for(i=1;i<(T-1)*n+1;i++)
	{
		a[i]=(a[i-1]+i)%13;
		
	} 
	long long num=0;
	for(i=0;i<T;i++)
{
	num+=a[i*n];
}	
	printf("%lld",num);	
	return 0;
	
}
2020-10-07 13:11:40
这是基础题 我giao
2020-08-29 17:08:32
6666666666666666666666666666666666666666666
2020-07-20 08:02:35
6666666666666666666666666666666666666666666
2020-07-16 05:09:39
大佬,我想知道 为什么不能直接用 sum+=(1+((i*n)*(1+i*n))/2)%k             sum初值给1
这样的方式计算,就是  
第一次  1
第二次 1+(1+2+3+...+n)%k
第三次 1+(1+2+3+...+2n)%k
第四次 1+(1+2+3+...+3n)%k
  这样做为什么错了、。。   不太明白
2020-05-11 01:46:32
首项为4 的那个  末项为 4+n-1
2020-05-11 01:44:45