P1174 互素】的更多相关文章

P1174 互素 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 对于某个数n,,我们这次的工作仅是求出小于n且和n互质的数的个数,,比如n=10时 1,3,7,9均与10互质 //互质的定义是gcd(a,b)=1 输入格式 输入只有一行,一个数N(1<=N<=2,000,000,000). 输出格式 输出也只有一行,输出和小于n且和n互质的数的个数 测试样例1 输入 10 输出 4 ----------------------------------…
问题:求1~r中有多少个数与n互素. 对于这个问题由容斥原理,我们有3种写法,其实效率差不多.分别是:dfs,队列数组,位运算. 先说说位运算吧: 用二进制1,0来表示第几个素因子是否被用到,如m=3,三个因子是2,3,5,则i=3时二进制是011,表示第2.3个因子被用到 LL Solve(LL n,LL r) { vector<LL> p; for(LL i=2; i*i<=n; i++) { if(n%i==0) { p.push_back(i); while(n%i==0) n/…
F - Strange Way to Express Integers Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1573 X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5012    Accepted Submission(s): 1667 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] =…
Biorhythms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2408    Accepted Submission(s): 1053 Problem Description Some people believe that there are three cycles in a person's life that start…
题意:给定整数n和r,求区间[1, r]中与n互素的数的个数. 详细见容斥定理 详细代码如下 int solve(int r, int n) { vector<int>p; p.clear(); for(int i = 2; i*i <= n; ++i) { if(n % i == 0) { p.push_back(i); while(n % i == 0) n /= i; } } if(n > 1) p.push_back(n); //可能n也是素数 int sum = 0; f…
void Solve(LL n){ ///分解质因数保存结果于p p.clear(); ; i*i<=n; i++) ){ p.push_back(i); ) n/=i; } ) p.push_back(n); } void dfs(LL k,LL t,LL s,LL n){ ///求与n互素个数 if(k==p.size()){ ) ans-=n/s; else ans+=n/s; return; } dfs(k+,t,s,n); dfs(k+,t+,s*p[k],n); } ///主函数内是…
P1174 打砖块 普通分组背包:50pts 题解说的啥????(大雾) 看了半天 $s[0/1][i][j]$表示第$i$列用$j$发子弹,最后一发是1/否0打在该列上的价值 $f[0/1][i][j]$表示截止到第$i$列共用$j$发子弹,最后一发是1/否0打在该列上的最大价值 每次转移分成先打/后打第$i$列的情况 #include<iostream> #include<cstdio> #include<cstring> #include<cctype>…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 17877   Accepted: 6021 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
#include<bits/stdc++.h>using namespace std;const long long mod = 998244353;typedef const long long ll;vector<long long>p;long long inv(long long x,long long y)//快速幂求逆元模板(以乘代除){    long long r=1;    while(y>0)    {        if(y&1)        …