2016亚洲区域赛现场赛china final A题

Problem A. Number Theory Problem
Input file: Standard Input Output file: Standard Ouptut Time limit: 1 second
Mr. Panda is one of the top specialists on number theory all over the world. Now Mr. Panda is investigating the property of the powers of 2. Since 7 is the lucky number of Mr. Panda, he is always interested in the number that is a multiple of 7. However, we know that there is no power of 2 that is a multiple of 7, but a power of 2 subtracted by one can be a multiple of 7. Mr. Panda wants to know how many positive integers less than 2N in the form of 2k −1 (k is a positive integer) that is divisible by 7. N is a positive interger given by Mr Panda. Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case contains only one positive interger N. Output For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the answer. Limits
• 1 ≤ T ≤ 100. • 1 ≤ N ≤ 105. Sample input and output Sample Input Sample Output 2 1 4 Case #1: 0 Case #2: 1

题意:问你有多少个整数形如2^k - 1且小于2^N的数能被7整除。

解题思路:直接快速幂搞一下就行,判断(2^k - 1)mod7 == 0就行。


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
const int mod = 7;
const int maxn=100005;
ll ans[maxn];

void pow_mod()
{
    int a,x,num=0;
    for(int i=1;i<maxn;i++)
    {
        ans[i]=1;
        x = i;
        a = 2;
        while(x)
        {
            if(x&1) ans[i] = (ans[i]*a)%mod;
            a = (a*a)%mod;
            x >>= 1;
        }
        if(ans[i]%mod==1) num++;
        ans[i] = num;
    }
}

int main()
{
    pow_mod();
    int t;
    scanf("%d",&t);
    for(int ca=1;ca<=t;ca++)
    {
        int n;
        scanf("%d",&n);
        printf("Case #%d: %d\n",ca,ans[n]);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值