【AC Saber】二进制
生活随笔
收集整理的這篇文章主要介紹了
【AC Saber】二进制
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 二進制中1的個數
- 64位整數乘法
二進制中1的個數
#include<cstdio> #include<iostream> using namespace std; int lowbit(int x) {return x&(-x); } int main(void) {int n; cin>>n;while(n--){int x; cin>>x;int cnt=0;while(x) x-=lowbit(x),cnt++;cout<<cnt<<" ";}return 0; }64位整數乘法
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long int LL; LL a,b,p; LL f(LL a,LL b,LL p) {int res=0;while(b){if(b&1) res=(res+a)%p;a=a*2;b>>=1;}return res%p; } int main(void) {cin>>a>>b>>p;cout<<f(a,b,p)<<endl;return 0; }總結
以上是生活随笔為你收集整理的【AC Saber】二进制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【AC Saber】双指针
- 下一篇: 【AC Saber】离散化