Lucky
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1443 Accepted Submission(s): 767
Problem Description
Chaos August likes to study the lucky numbers.
For
a set of numbers S,we set the minimum non-negative integer,which can't
be gotten by adding the number in S,as the lucky number.Of course,each
number can be used many times.
Now,
given a set of number S, you should answer whether S has a lucky
number."NO" should be outputted only when it does have a lucky
number.Otherwise,output "YES".
Input
The first line is a number T,which is case number.
In each case,the first line is a number n,which is the size of the number set.
Next are n numbers,means the number in the number set.
1≤n≤105,1≤T≤10,0≤ai≤109.
Output
Output“YES”or “NO”to every query.
Sample Input
1
1
2
Sample Output
NO
只要有0和1就行了;
#include
#include
#include
#include
#include
#include
#include
#include
Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2913 Accepted Submission(s): 976
Problem Description
Holion August will eat every thing he has found.
Now there are many foods,but he does not want to eat all of them at once,so he find a sequence.
fn=⎧⎩⎨⎪⎪1,ab,abfcn−1fn−2,n=1n=2otherwise
He gives you 5 numbers n,a,b,c,p,and he will eat fn foods.But there are only p foods,so you should tell him fn mod p.
Input
The first line has a number,T,means testcase.
Each testcase has 5 numbers,including n,a,b,c,p in a line.
1≤T≤10,1≤n≤1018,1≤a,b,c≤109,p is a prime number,and p≤109+7.
Output
Output one number for each case,which is fn mod p.
Sample Input
1
5 3 3 3 233
Sample Output
190
1e18,必须得logn的算法;快速幂!前几项手算可以发现;最后的结果都有a^b;那么我们先不看这个;除这个以外,还有一个多项式;不妨设为g(n);可以发现 g(n)=c*g(n-1)+g(n-2)+1;------> 矩阵快速幂;构造则非常简单了;由于我们fn=a^x mod p;由费马小定理: a^x = a^( x mod ( p-1) )mod p;所以对于指数这一项,我们可以降幂;那么问题就解决了;其实就是快速幂套一个快速幂的问题;
#include
#include
#include
#include
#include
#include
#include
#include
Segment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2422 Accepted Submission(s): 896
Problem Description
Silen August does not like to talk with others.She like to find some interesting problems.
Today she finds an interesting problem.She finds a segment x+y=q.The segment intersect the axis and produce a delta.She links some line between (0,0) and the node on the segment whose coordinate are integers.
Please calculate how many nodes are in the delta and not on the segments,output answer mod P.
Input
First line has a number,T,means testcase number.
Then,each line has two integers q,P.
q is a prime number,and 2≤q≤1018,1≤P≤1018,1≤T≤10.
Output
Output 1 number to each testcase,answer mod P.
Sample Input
1
2 107
Sample Output
0
sum=(q-1)*(q-2)/2;用快速乘防止爆longlong;当然用 java也可;
#include
#include
#include
#include
#include
#include
#include
#include
EPFL - Fighting