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).

2个回答

Mir.Yang #include<iostream> using namespace std; int re[10000]; int main() { int a,b,n; re[1]=1;re[2]=1; while(cin>>a>>b>>n&&(a||b||n)){ int i; for(i=3;i<10000;i++){ re[i]=(a*re[i-1]+b*re[i-2])%7; if(re[i]==1&&re[i-1]==1) break; } n=n%(i-2); re[0]=re[i-2]; cout<<re[n]<<endl; } return 0; }
6 个月之前 回复
Mir.Yang 其实可以不需要知道周期的：附上源码：
6 个月之前 回复
LinSeanYu 不理解前，看了你的话也还是会不理解，但是我昨晚想明白了，今天看了你的回复，就觉得很有道理，哈哈
4 年多之前 回复

C++代码：
#include
const int N=55;
int dp[N];
int getRes(int A,int B,int n){
if(n==1||n==2)
r......

----------------------Hi，地球人，我是问答机器人小S，上面的内容就是我狂拽酷炫叼炸天的答案，除了赞同，你还有别的选择吗？

http://acm.hdu.edu.cn/showproblem.php?pid=2022 杭电求解2022，带解析的那种，【害羞】

#include<stdio.h> int main(void) { int T = 0, a = 0, count_a = 0, count_b = 0; long long A[1000] = { 0 }, B[1000] = { 0 }, SUM[1000] = { 0 }; scanf("%d", &T); while (T > 0) { a++; scanf("%lld %lld", &A[a], &B[a]); SUM[a] = A[a] + B[a]; T--; } for (T = 1; T <= a; T++) { printf("Case %d:\n%lld + %lld = %lld\n\n", T, A[T], B[T], SUM[T]); } } 为什么不能这么做？？每次提交显示wrong answer！why？

![图片说明](https://img-ask.csdn.net/upload/201510/15/1444870735_573916.png) 我的代码 #include <stdio.h> int main(){ int n, i; int a, b; int x, sum; while(scanf("%d", &n) != EOF){ for (i = 0; i < n; i++){ scanf("%d", &a); for (b = 0; b < a; b++){ sum = 0; scanf("%d", &x); sum = sum + x; printf("%d", sum); printf("\n"); } } } return 0; }

import java.math.BigInteger; import java.util.Scanner; public class A1042 { private static Scanner sc; public static void main(String []args){ sc = new Scanner(System.in); BigInteger n = sc.nextBigInteger(); while(n.intValue()<=10000){ if(!n.equals(BigInteger.valueOf(1))){ n = n.multiply(n.subtract(BigInteger.valueOf(1))); } System.out.println(n); n = sc.nextBigInteger(); } } } 为什么自己运行结果是正确的却编译不通过，提示Compilation Error

#include<stdio.h> #include<string> int c[10086]; int main() { int i,j,l,n,k,h; while(scanf("%d",&n)!=EOF) { memset(c,0,sizeof(c)); c[0]=1; k=0; if(n==0) printf("1\n"); else { for(j=1;j<=n;j++) { for(i=0;i<=k;i++) { c[i]=c[i]*j; } for(h=0;h<=k;h++) { if(c[h]>9999) { c[h+1]=c[h+1]+c[h]/10000; c[h]=c[h]%10000; if(c[k+1]>0) //*为什么这个if判断不能少 按道理不是一定会有c[k+1]>0吗，没有这一句我的结果前面多了两个0*// k++; } } } for(l=k;l>=0;l--) { if(l==k) printf("%d",c[l]); else { if(c[l]<10&&c[l]>=0) printf("000%d",c[l]); else if(c[l]<100&&c[l]>=10) printf("00%d",c[l]); else if(c[l]<1000&&c[l]>=100) printf("0%d",c[l]); else if(c[l]>=1000) printf("%d",c[l]); } } printf("\n"); } } return 0; }

#include<stdio.h> #include<string.h> main() { static char arr[20][100000]; int i,j,a,n=0,t,result=0,sum=0; scanf("%d",&t);//准备输入几行t=2 if(t>=1&&t<=20){ while(n<t){ if(scanf("%d",&i) && i>=1 && i<=100000){ // 第t输入出i个数, j =0; arr[n][j++] = i;//第一个位置记录的是 每个一维数组的长度，以免第一个元素出现0， 用strlen 会失效 while(j<=i && scanf("%d",&a)!=EOF){ if(a>=-1000 && a<=1000) arr[n][j++] = a; } } n++; } } for(i=0;i<t;i++){// t 是 输入几行 int len = arr[i][0]; int start,end,k;// 从新的位置开始统计和最大的组合序列 for(j=1;j<=len;j++){// 循环次数 for(k=j;k<len;k++){ result += arr[i][k]; if(result>sum){ sum = result; start = j; end = k; } } result = 0; } printf("Case %d:\n",i+1); printf("%d %d %d",sum,start,end); if(i+1<t){ printf("\n\n"); }else printf("\n"); sum =0; } }

#include<stdio.h> int main() { long n,r; char a[10000]; while(scanf("%d%d",&n,&r) == 2) { if(n == 0) printf("0\n"); else { int i = 0; if(n<0){n=-n;printf("-");} while(n > 0) { a[i++] = n%r; n=n/r; } int j = i-1; for(; j >= 0; j--) { if(a[j] > 10) printf("%c",a[j]-10+'A'); else printf("%d",a[j]); } putchar('\n'); } } return 0; }

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int m=0; int n=0; while(in.hasNext()){ m=in.nextInt(); n=in.nextInt(); if(m<n){ narcissus(m,n); } } } public static void narcissus(int m, int n){ int k=0; boolean mark = false; for(int i=m; i<=n; i++){ int sum=0; k=i; while(k!=0){ sum=sum+(k%10)*(k%10)*(k%10); k=k/10; } if(i==sum) { mark = true; System.out.print(i+" "); } } if(mark==false){ System.out.println("NO"); } System.out.println(); } }

``` #include<iostream> #include<string> using namespace std; int main() { string in; char temp; int flag, flagv; int vowel = 0; int consonant = 0; while (cin >> in) { if (in == "end") break; flag = 1; flagv = 0; temp = '~'; for (int i = 0; i < in.size(); i++) { if (in[i] == 'a'||in[i]=='e'||in[i]=='i'||in[i]=='o'||in[i]=='u') { consonant = 0; flagv = 1; vowel++; if (vowel == 3) { flag = 0; break; } } else { vowel = 0; consonant++; if (consonant == 3) { flag = 0; break; } } if (temp == in[i] &&in[i]!='e'&&in[i]!='o') { flag = 0; break; } else temp = in[i]; } cout << "<" << in << "> " << "is "; flag == 1&&flagv==1 ? cout << "acceptable" : cout << "not acceptable"; cout << endl; } return 0; } ```

#include <stdio.h> #include <string.h> int main(){ char ax[20][1000], bx[20][1000], temp[1000], a[1000], b[1000]; int n, lena, lenb; while(scanf("%d",&n)!= EOF){ for(int i = 0;i < n;i++){ scanf("%s %s",ax[i],bx[i]); } for(int i = 0;i < n;i++){ int num[1001] = {0}; strcpy(a,ax[i]); strcpy(b,bx[i]); lena = strlen(a); lenb = strlen(b); if(lena < lenb){ strcpy(temp,a); strcpy(a,b); strcpy(b,temp); lena = strlen(a); lenb = strlen(b); } int carry = 0; int len = lena; int add = 0; for(int j = 0;j < len;j++){ if(lenb > 0){ add = a[lena-1] - '0' + b[lenb-1] - '0' + carry; num[lena] = add % 10; carry = add / 10; lena--; lenb--; } else{ add = a[lena-1] - '0' + carry; num[lena] = add % 10; carry = add / 10; lena--; lenb--; } } num[0] = carry; printf("case %d:\n",i+1); printf("%s + %s = ",a,b); if(num[0] == 0){ for(int j = 1;j <= len;j++){ printf("%d",num[j]); } printf("\n"); } else{ for(int j = 0;j <= len;j++){ printf("%d",num[j]); } printf("\n"); } printf("\n"); } } return 0; } 经典的大数相加，题目如下： Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000. Output For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases. Sample Input 2 1 2 112233445566778899 998877665544332211 Sample Output Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110 程序跑图贴在下面，大牛们帮看看吧

#include<iostream> #include<cmath> #include<iomanip> using namespace std; int main() { int N,i,j,k=0; double min; while (cin >> N&&N) { double *x = new double[N]; double *y = new double[N]; double *d = new double[N*(N-1)]; for (i = 0; i < N; i++) cin >> x[i] >> y[i]; for (i = 0; i < N-1; i++) { for (j = i + 1; j < N; j++) { if (x[i] == x[j] && y[i] == y[j]) d[k] = 0; else d[k] = (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]); k++; } } min = d[0]; for (k = 0; k < N*(N - 1) / 2; k++) if (min > d[k]) min = d[k]; if(min!=0) min = sqrt(min)/2; cout << setprecision(2) << fixed << min << endl; delete []x, y, d; } return 0; } 连续输入两次数据： 2 1 1 1 1 为什么第一次是0.00，第二次是-nan(ind)

ACM OJ 给定一个日期，输出这个日期是该年的第几天。

The Team of ACM/ICPC
Problem Description There are 3 people in a team of ACM/ICPC. Every member of the team will occasionally make some mistakes in the contest. So Mr.F tests every one and everybody gets a Mistake Value x. If the Mistake Values of the 3 members of a team are respectively a, b, c, then the Mistake Value of the team is m = min{ |a-b|, |b-c|, |c-a| }. Your job is to find the best plan to minimize M which is the sum of all the Mistake Value of teams. Input In the first line, there are two integers N and K. N is the number of people who will make teams and K is the number of teams which is supposed to make. (3<= N <=100000) (0<= k <= N/3 ) There are N lines followed. Each line has an integer D, which is the Mistake Value of the person.(0<=D<=1000000000) Output Print the minimal M in one line. Sample Input 7 2 1 5 3 2 4 7 9 Sample Output 2

Java学习的正确打开方式

linux系列之常用运维命令整理笔录

python学习方法总结(内附python全套学习资料)

JAVA 基础练习题

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。

2019年11月中国大陆编程语言排行榜
2019年11月2日，我统计了某招聘网站，获得有效程序员招聘数据9万条。针对招聘信息，提取编程语言关键字，并统计如下： 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...

C++知识点 —— 整合（持续更新中）

《奇巧淫技》系列-python！！每天早上八点自动发送天气预报邮件到QQ邮箱

Python实例大全（基于Python3.7.4）

【Linux系统编程】Linux信号列表
00. 目录 文章目录00. 目录01. Linux信号编号02. 信号简介03. 特殊信号04. 附录 01. Linux信号编号 在 Linux 下，每个信号的名字都以字符 SIG 开头，每个信号和一个数字编码相对应，在头文件 signum.h 中，这些信号都被定义为正整数。信号名定义路径：/usr/include/i386-linux-gnu/bits/signum.h 要想查看这些信号和...
JavaScript 为什么能活到现在？

Python 编程开发 实用经验和技巧
Python是一门很灵活的语言，也有很多实用的方法，有时候实现一个功能可以用多种方法实现，我这里总结了一些常用的方法和技巧，包括小数保留指定位小数、判断变量的数据类型、类方法@classmethod、制表符中文对齐、遍历字典、datetime.timedelta的使用等，会持续更新......