A. Number Theory Problem

题目大意:计算小于2^n,且满足2^k-1并且是7的倍数的个数

思路:优先打表,数据不大,1e5,然后求个前n项和

#include<bits/stdc++.h>
using namespace std;
const int N=1E5+1;
int arr[N];

void inint(int x){
    int t=1;
    for(int i=1;i<=x;i++){
        t<<=1;
        t%=7;
        if(t==1) arr[i]=1;
    }

    for(int i=1;i<=x;i++)     arr[i]=arr[i]+arr[i-1];
}

void solve(int xx){
    int n;
    cin>>n;
    printf("Case #%d: %d\n",xx,arr[n]);
}
int main(){
    inint(N);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) solve(i);
    return 0;
}

原文地址:https://www.cnblogs.com/Accepting/p/11625651.html

时间: 2024-08-01 15:46:18

A. Number Theory Problem的相关文章

CodeForces 1325E - Ehab&#39;s REAL Number Theory Problem【质因子+】

题意: ??给定一个数组 \(a\) ,数组中任意一个元素的因子数不超过 \(7\) ,找出一个最短的子序列,满足该子序列之积为完全平方数.输出其长度. 数据范围:\(1≤n≤10^5,1≤a_i≤10^6\) 分析: ??首先,对于数组中的每个元素,如果其因子中包含有一个完全平方数,那么可以把该完全平方数除去,不影响最后的结果. ??然后,可以发现,当一个数的因子个数 \(\leq 7\) 时,其包含的质因子个数 \(\leq 2\).(如果有3个质因子,那么至少有 \(8\) 个因子)当我们

hdu-2685I won&#39;t tell you this is about number theory(数论)

题目链接: I won't tell you this is about number theory Problem Description To think of a beautiful problem description is so hard for me that let's just drop them off. :)Given four integers a,m,n,k,and S = gcd(a^m-1,a^n-1)%k,calculate the S. Input The fi

Acdream 1114 Number theory 莫比乌斯反演

http://acdream.info/problem?pid=1114 题目大意,给你一个序列a,求出这个序列中互质数的有多少对.其中所有的整数的都小于等于222222. f(d) 为 gcd 恰好为 d 的数的对数, F(d) 为 gcd 为 d 的倍数的对数, μ(d) 表示莫比乌斯函数 F(d) = ∑ f(n) 其中( n % d == 0 ) 莫比乌斯反演一下就可以得到, f(d) = ∑ μ(n / d) * F(n) 其中( n % d == 0) 所以我们最后所要的答案就是 f

Number Theory(数论-对数)

X - Number Theory Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. B

How to solve the SVDI SN Number Display Problem

Yesterday we have learn how to find the SVDI Serial Number, today one of customer from UK look our article and ask us, If i have problem of the SN number display , how can I sort it out? Please do not worry,  here we would tell you the detail steps h

2013年北京师范大学新生程序设计竞赛网络赛--D. Number theory(模拟取余)

D. Number theory Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 34055 Font Size:  +   - 数学不仅是简单而且是美的.数学很有趣,但是数学中也有很多难题,比如哥德巴赫猜想.各种欧拉定理.拉格朗日中值定理.费马定理等.今天小若遇

hdu 2685 I won&#39;t tell you this is about number theory

#include<stdio.h>#include<string.h>#define LL __int64 LL mult_mod(LL a,LL b,LL c){    a%=c;    b%=c;    LL ret=0;    while(b)    {        if(b&1){ret+=a;ret%=c;}        a<<=1;        if(a>=c)a%=c;        b>>=1;    }    retur

A1-2017级算法上机第一次练习赛 P ModricWang&#39;s Number Theory II

题目描述 ModricWang has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1. ModricWang can perform two types of operations: Choose a number an

BZOJ 1114 Number theory(莫比乌斯反演+预处理)

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=71738 题意:给你一个整数序列a1, a2, a3, ... , an.求gcd(ai, aj) = 1 且 i < j的对数. 思路:利用莫比乌斯反演很快就能得到公式,但是求解时我们要知道序列中1, 2, 3, ... , max(a1, a2, ... , an)的倍数各是多少.我们用num[i]=k,来表示序列中有k个数是i的倍数,那么这部分对结果的影响是m