1409221809-hd-Number Sequence

部署运行你感兴趣的模型镜像

Number Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1328    Accepted Submission(s): 522


 

Problem Description
A number sequence is defined as follows:

f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.

Given A, B, and n, you are to calculate the value of f(n).
Input
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.
Output
For each test case, print the value of f(n) on a single line.
Sample Input
1 1 3
1 2 10
0 0 0
Sample Output
2
5
题目大意
      根据题目给定的公式解决。
解题思路
       这道题用到了同余定理,但是如果单纯的运用同余定理进行暴力求解,会超出内存。最好的方法是仔细观察题目给定的公式,为什么要对7取余呢?这么大的数据范围肯定会存在循环节,循环电石什么呢?其实我也不知道怎么找,只知道48是一个循环,,
代码
#include<stdio.h>
int f[48];
int main()
{
	int a,b,n;
	int i,j,k;
	while(scanf("%d%d%d",&a,&b,&n)&&a+b+n)
	{
		f[1]=f[2]=1;
		for(i=3;i<=n%48;i++)
	//要找循环节 
		{
			j=f[i-1]*a%7;
			k=f[i-2]*b%7;
			f[i]=(j+k)%7;
		}
		printf("%d\n",f[n%48]);
	}
	return 0;
}

您可能感兴趣的与本文相关的镜像

HunyuanVideo-Foley

HunyuanVideo-Foley

语音合成

HunyuanVideo-Foley是由腾讯混元2025年8月28日宣布开源端到端视频音效生成模型,用户只需输入视频和文字,就能为视频匹配电影级音效

D5 Sorting BAM: D5 [bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files Usage: samtools sort [options...] [in.bam] Options: -l INT Set compression level, from 0 (uncompressed) to 9 (best) -u Output uncompressed data (equivalent to -l 0) -m INT Set maximum memory per thread; suffix K/M/G recognized [768M] -M Use minimiser for clustering unaligned/unplaced reads -R Do not use reverse strand (only compatible with -M) -K INT Kmer size to use for minimiser [20] -I FILE Order minimisers by their position in FILE FASTA -w INT Window size for minimiser indexing via -I ref.fa [100] -H Squash homopolymers when computing minimiser -n Sort by read name (natural): cannot be used with samtools index -N Sort by read name (ASCII): cannot be used with samtools index -t TAG Sort by value of TAG. Uses position as secondary index (or read name if -n is set) -o FILE Write final output to FILE rather than standard output -T PREFIX Write temporary files to PREFIX.nnnn.bam --no-PG Do not add a PG line --template-coordinate Sort by template-coordinate --input-fmt-option OPT[=VAL] Specify a single input file format option in the form of OPTION or OPTION=VALUE -O, --output-fmt FORMAT[,OPT[=VAL]]... Specify output format (SAM, BAM, CRAM) --output-fmt-option OPT[=VAL] Specify a single output file format option in the form of OPTION or OPTION=VALUE --reference FILE Reference sequence FASTA FILE [null] -@, --threads INT Number of additional threads to use [0] --write-index Automatically index the output files [off] --verbosity INT Set level of verbosity D5 D6 Sorting BAM: D6 [bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files Usage: samtools sort [options...] [in.bam] Options: -l INT Set compression level, from 0 (uncompressed) to 9 (best) -u Output uncompressed data (equivalent to -l 0) -m INT Set maximum memory per thread; suffix K/M/G recognized [768M] -M Use minimiser for clustering unaligned/unplaced reads -R Do not use reverse strand (only compatible with -M) -K INT Kmer size to use for minimiser [20] -I FILE Order minimisers by their position in FILE FASTA -w INT Window size for minimiser indexing via -I ref.fa [100] -H Squash homopolymers when computing minimiser -n Sort by read name (natural): cannot be used with samtools index -N Sort by read name (ASCII): cannot be used with samtools index -t TAG Sort by value of TAG. Uses position as secondary index (or read name if -n is set) -o FILE Write final output to FILE rather than standard output -T PREFIX Write temporary files to PREFIX.nnnn.bam --no-PG Do not add a PG line --template-coordinate Sort by template-coordinate --input-fmt-option OPT[=VAL] Specify a single input file format option in the form of OPTION or OPTION=VALUE -O, --output-fmt FORMAT[,OPT[=VAL]]... Specify output format (SAM, BAM, CRAM) --output-fmt-option OPT[=VAL] Specify a single output file format option in the form of OPTION or OPTION=VALUE --reference FILE Reference sequence FASTA FILE [null] -@, --threads INT Number of additional threads to use [0] --write-index Automatically index the output files [off] --verbosity INT Set level of verbosity [E] Failed to create sorted BAM: /share/home/wangluyao/bwa_results/D6_sorted.bam
09-17
static void vrrp_update_pkt(vrrp_t *vrrp, uint8_t prio, struct sockaddr_storage *addr) { char *bufptr = vrrp->send_buffer; log_message(LOG_INFO, "%s:%d sent buffer is %s \n", __func__, __LINE__,bufptr); vrrphdr_t *hd; #ifdef _WITH_VRRP_AUTH_ bool final_update; unicast_peer_t *peer = NULL; #endif uint32_t new_saddr = 0; uint32_t new_daddr; #ifdef _WITH_VRRP_AUTH_ /* We will need to be called again if there is more than one unicast peer, so don't calculate checksums */ if (!list_empty(&vrrp->unicast_peer)) peer = list_first_entry(&vrrp->unicast_peer, unicast_peer_t, e_list); final_update = (!peer || list_is_last(&peer->e_list, &vrrp->unicast_peer) || addr); #endif if (vrrp->family == AF_INET) { bufptr += sizeof(struct iphdr); #ifdef _WITH_VRRP_AUTH_ if (vrrp->auth_type == VRRP_AUTH_AH) bufptr += sizeof(ipsec_ah_t); #endif } hd = PTR_CAST(vrrphdr_t, bufptr); hd->test_num = htons(1234); if (hd->priority != prio) { if (vrrp->family == AF_INET) { /* HC' = ~(~HC + ~m + m') */ uint16_t *prio_addr = PTR_CAST(uint16_t, ((char *)&hd->priority - (((char *)hd -(char *)&hd->priority) & 1))); uint16_t old_val = *prio_addr; hd->priority = prio; hd->chksum = csum_incremental_update16(hd->chksum, old_val, *prio_addr); } else hd->priority = prio; } if (vrrp->family == AF_INET) { struct iphdr *ip = PTR_CAST(struct iphdr, (vrrp->send_buffer)); if (!addr) { /* kernel will fill in ID if left to 0, so we overflow to 1 */ if (!++vrrp->ip_id) ++vrrp->ip_id; ip->id = htons(vrrp->ip_id); } else { /* If unicast address */ if (vrrp->version == VRRP_VERSION_2) ip->daddr = inet_sockaddrip4(addr); else { new_daddr = inet_sockaddrip4(addr); if (ip->daddr != new_daddr) { #ifdef _WITH_UNICAST_CHKSUM_COMPAT_ if (vrrp->unicast_chksum_compat < CHKSUM_COMPATIBILITY_MIN_COMPAT) #endif hd->chksum = csum_incremental_update32(hd->chksum, ip->daddr, new_daddr); ip->daddr = new_daddr; } } } /* Has the source address changed? */ if (!vrrp->saddr_from_config && ip->saddr != PTR_CAST(struct sockaddr_in, &vrrp->saddr)->sin_addr.s_addr) { if (vrrp->version == VRRP_VERSION_2) ip->saddr = PTR_CAST(struct sockaddr_in, &vrrp->saddr)->sin_addr.s_addr; else { new_saddr = PTR_CAST(struct sockaddr_in, &vrrp->saddr)->sin_addr.s_addr; hd->chksum = csum_incremental_update32(hd->chksum, ip->saddr, new_saddr); ip->saddr = new_saddr; } } //jhw if (vrrp->version == VRRP_VERSION_2) { size_t len = sizeof(vrrphdr_t) + hd->naddr * sizeof(struct in_addr) + VRRP_AUTH_LEN; uint16_t new_csum = in_csum(PTR_CAST(uint16_t, hd), len, 0, NULL); hd->chksum = new_csum; } else if (vrrp->version == VRRP_VERSION_3) { size_t len = sizeof(vrrphdr_t) + hd->naddr * sizeof(struct in_addr); uint16_t new_csum = in_csum(PTR_CAST(uint16_t, hd), len, 0, NULL); hd->chksum = new_csum; } #ifdef _WITH_VRRP_AUTH_ if (vrrp->auth_type == VRRP_AUTH_AH) { unsigned char digest[MD5_DIGEST_LENGTH]; ipsec_ah_t *ah = PTR_CAST(ipsec_ah_t, (vrrp->send_buffer + sizeof (struct iphdr))); if (new_saddr) ah->spi = new_saddr; if (!addr) { /* Processing sequence number. Cycled assumed if 0xFFFFFFFD reached. So the MASTER state is free for another srv. Here can result a flapping MASTER state owner when max seq_number value reached. => We REALLY REALLY REALLY don't need to worry about this. We only use authentication for VRRPv2, for which the adver_int is specified in whole seconds, therefore the minimum adver_int is 1 second. 2^32-3 seconds is 4294967293 seconds, or in excess of 136 years, so since the sequence number always starts from 0, we are not going to reach the limit. In the current implementation if counter has cycled, we stop sending adverts and become BACKUP. We are ever the optimist and think we might run continuously for over 136 years without someone redesigning their network! If all the master are down we reset the counter for becoming MASTER. */ if (vrrp->ipsecah_counter.seq_number > 0xFFFFFFFD) { vrrp->ipsecah_counter.cycle = true; } else { vrrp->ipsecah_counter.seq_number++; } ah->seq_number = htonl(vrrp->ipsecah_counter.seq_number); } if (final_update) { struct iphdr iph = *ip; /* zero the ip mutable fields */ iph.tos = 0; iph.frag_off = 0; if (!list_empty(&vrrp->unicast_peer)) iph.ttl = 0; /* Compute the ICV & trunc the digest to 96bits => No padding needed. -- rfc2402.3.3.3.1.1.1 & rfc2401.5 */ memset(&ah->auth_data, 0, sizeof(ah->auth_data)); hmac_md5(PTR_CAST_CONST(unsigned char, &iph), sizeof iph, PTR_CAST_CONST(unsigned char, ah), vrrp->send_buffer_size - sizeof(struct iphdr), vrrp->auth_data, sizeof(vrrp->auth_data), digest); memcpy(ah->auth_data, digest, HMAC_MD5_TRUNC); } } #endif } log_message(LOG_INFO, "%s:%d sent buffer is %s \n", __func__, __LINE__,bufptr); }这个函数做了哪些工作,通俗地解释下,把关键的信息详细说明下
07-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值