InputThere are no more than 50 test cases. Each case only contains a positivse integer n in a line. 1≤n≤10181≤n≤1018 OutputFor each test case, output an integer indicates the number of positive integers k satisfy kk≤nkk≤n in a line.Sample Input
14
Sample Output
12
A是最好做的,找到那个最大的数,15吧
写快速幂只是不想循环,感觉也很麻烦
#includeusing namespace std;typedef long long ll;ll la(int n){ ll ans=1,base=n; while(n) { if(n&1)ans=ans*base; n>>=1,base=base*base; } return ans;}int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); ll n; while(cin>>n) { int i; for(i=1;i<16;i++) if(la(i)>n)break; cout< <<"\n"; } return 0;}
InputThere are no more than 15 test cases. Each test case begins with two positive integers n and p in a line, indicate the number of positive integers and the number of queries. 2≤n,q≤1052≤n,q≤105 Then n non-negative integers a1,a2,⋯,ana1,a2,⋯,an follows in a line, 0≤ai≤1090≤ai≤109 for each i in range[1,n]. After that there are q positive integers p1,p2,⋯,pqp1,p2,⋯,pqin q lines, 1≤pi≤n1≤pi≤n for each i in range[1,q].OutputFor each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except apap in a line. Sample Input
3 31 1 1123
Sample Output
1 1 01 1 01 1 0
让你求n个数除x这个数的按位与和按位或还有异或和,明明前缀后缀最方便,sb写了一个统计二进制位的
#includeusing namespace std;typedef long long ll;const int N=1e5+5;int a[N],num[31],f[31];int la(int n){ int i=0; while(n) { if(n&1)num[i]++; n>>=1,i++; }}int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n,q; while(cin>>n>>q) { int xor1=0; memset(num,0,sizeof num); for(int i=0; i >a[i],xor1^=a[i]; for(int i=0; i >x; x--; for(int i=0; i<31; i++) f[i]=num[i]; int i=0; int t=a[x]; while(t) { if(t&1)f[i]--; t>>=1,i++; } int and1=0,or1=0; for(int i=30;i>=0;i--) { and1=and1*2+(f[i]==n-1); or1=or1*2+(f[i]!=0); } cout< <<" "< <<" "<<(xor1^a[x])<<"\n"; } } return 0;}
InputThe input contains several test cases. For each test case, the first line contains one integer n(1≤n≤1061≤n≤106). Then the next line contains n space-separated integers aiai (1≤ai≤n1≤ai≤n) OutputFor each test case, output the answer in a line. Sample Input
71 2 3 4 5 6 791 1 1 2 2 2 3 3 362 2 3 3 3 3 61 2 3 3 4 5
Sample Output
2432
Hint
Case 1(1,2,3)(4,5,6)Case 2(1,2,3)(1,1)(2,2)(3,3)Case 3(2,2)(3,3)(3,3)Case 4(1,2,3)(3,4,5)
贪心组对子和顺子就好了
#includeusing namespace std;int n,x,a[1000005];int main(){ while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof a); int sum=0; for(int i=0;i
我是只考虑第一张的
#include#include const int N=1e5+5;int a[N];int main(){ int n; while(~scanf("%d",&n)) { memset(a,0,sizeof(int)*(n+5)); for(int i=0; i
InputThere are no more than 5000 test cases.
Each test case only contains one positive integer n in a line. 1≤n≤10181≤n≤1018 OutputFor each test cases, output the answer mod 1000000007 in a line. Sample Input12
Sample Output
15
暴力算几项,肯定是前四项推出来第五项的,
暴力跑一下
然后暴力猜系数,
#includeusing namespace std;typedef long long ll;const int MD=1e9+7;int A[5]={ 0,1,5,11,36};struct Matrix{ ll a[4][4]; Matrix() { memset(a,0,sizeof(a)); } Matrix operator*(const Matrix y) { Matrix ans; for(int i=0; i<4; i++) for(int j=0; j<4; j++) for(int k=0; k<4; k++) ans.a[i][j]=(ans.a[i][j]+a[i][k]*y.a[k][j]+MD)%MD; return ans; } void operator=(const Matrix b) { for(int i=0; i<4; i++) for(int j=0; j<4; j++) a[i][j]=b.a[i][j]; }};ll la(ll x){ Matrix ans,t; t.a[0][0]=t.a[0][1]=t.a[1][2]=t.a[2][3]=t.a[2][0]=1; t.a[3][0]=-1,t.a[1][0]=5; ans.a[0][0]=36,ans.a[0][1]=11,ans.a[0][2]=5,ans.a[0][3]=1; while(x) { if(x&1)ans=ans*t; t=t*t; x>>=1; } return ans.a[0][0];}int main(){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); ll n; while(cin>>n) { if(n<5)cout< <<"\n"; else cout< <<"\n"; } return 0 ;}