• Number Sequence Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 65 Accepted Submission(s) : 27 Problem Description A number sequence is defined...
Number Sequence
Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 65   Accepted Submission(s) : 27
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
Author
CHEN, Shunbao
Source
ZJCPC2004
#include <stdio.h>
int fn(int a,int b,int n);
int main()
{
int n,a,b;
scanf("%d %d %d",&a,&b,&n);
while(a!=0||b!=0||n!=0)
{
a=a%7;
b=b%7;
n=n%48;
printf("%d\n",fn(a,b,n));
scanf("%d %d %d",&a,&b,&n);
}
return 0;
}
int fn(int a,int b,int n)
{
if(n==1)
return 1;
else if(n==2)
return 1;
else
return (a*fn(a,b,(n-1))+b*fn(a,b,(n-2)))%7;
}



展开全文
• Number SequenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 41681 Accepted: 12158DescriptionA single positive integer i is given. Write a program to find the digit located in the ...
Number SequenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 41681 Accepted: 12158DescriptionA single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive integer numbers ranging from 1 to k, written one after another. For example, the first 80 digits of the sequence are as follows: 11212312341234512345612345671234567812345678912345678910123456789101112345678910InputThe first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by one line for each test case. The line for a test case contains the single integer i (1 ≤ i ≤ 2147483647)OutputThere should be one output line per test case containing the digit located in the position i.Sample Input2
8
3Sample Output2
2log10(n)+1可以得到数n的长度Len[n]表示1到n这一段的总长度s[n]表示第一段到第n段的总长度
先确定第n位在哪段中，然后从1开始枚举确定第n位在哪个数中。设k是这个数最后一位的位置，这个数为num，则第n位的数是num/pow(10,k-n)%10 (掐头去尾)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
LL s[50005];
LL Len[50005];

#include <cmath>
int main(){
Len[1]=1;
for(int i=2;i<=50000;i++){
Len[i]=Len[i-1]+log10(i*1.0)+1;
}
s[1]=1;
for(int i=2;i<=50000;i++){
s[i]=s[i-1]+Len[i];
}
LL n;
int T;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
int i;
for(i=1;s[i]<n;i++);
i--;
n-=s[i];
int pos;
int k=0;
for(pos=1;n>k;pos++){
k+=(log10(pos*1.0)+1);
}
pos--;
int res;
res=pos/(int)pow(10*1.0,(k-n)*1.0);
res%=10;
printf("%d\n",res);

}
return 0;
}  
展开全文
• how to use ax Number Sequence

...