【2015沈阳现场A】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sxy201658506207/article/details/84672953

题意:求个一个n 求2^n-1能被7整除得有多少个,(1,2,....n)
简单得同余方程

#include<bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
ll qpow(ll a,ll n)
{
    ll res = 1;
    while(n)
    {
        if(1&n) res = (res*a)%7;
        a = (a*a)%7;
        n>>=1;
    }
    if(res%7 == 1) return 1;
    else return 0;
}
int main()
{
    int n;
    int k;
    cin>>n;
    for(int ca=1;ca<=n;++ca)
    {
        ll ans=0;
        cin>>k;
        for(int p=1;p<=k;++p)
            if(qpow(2,p)) ans++;
        cout<<"Case #"<<ca<<": "<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sxy201658506207/article/details/84672953