This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
string precomp[505];
int n,k;
string add(string a,string b){
string ans="";
int carry=0;
int la=(int)a.length(),lb=(int)b.length();
if(la>lb){
swap(la,lb);
swap(a,b);
}
for(int i=0;i<la;i++){
int A=a[la-i-1]-'0',B=b[lb-i-1]-'0';
ans=ans+(char)((A+B+carry)%10+'0');
if(A+B+carry>=10)carry=1;
else carry=0;
}
for(int i=la;i<lb;i++){
int B=b[lb-i-1]-'0'; //A=0
ans=ans+(char)((B+carry)%10+'0');
if(B+carry>=10)carry=1;
else carry=0;
}
if(carry==1)ans=ans+"1";
reverse(ans.begin(),ans.end());
return ans;
}
string lol(long long seglen,int parity){
string ans="0";
if(parity==0){
for(int i=0;i<n;i++){
if((i/seglen)%2==0)ans=add(ans,precomp[i]);
}
}else{
for(int i=0;i<n;i++){
if((i/seglen)%2==1)ans=add(ans,precomp[i]);
}
}
return ans;
}
int main(){
precomp[0]="1";
for(int i=1;i<505;i++){
precomp[i]=add(precomp[i-1],precomp[i-1]);
}
scanf("%d%d",&n,&k);
for(long long i=0;i<k;i++){
if((1LL<<i)>n)break;
string s1=lol(1LL<<i,0),s2=lol(1LL<<i,1);
printf("A=((A&%s)+((A&%s)>>%lld))\n",s1.c_str(),s2.c_str(),(1LL<<i));
}
}
Compilation message (stderr)
popcount.cpp: In function 'int main()':
popcount.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |