比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA。回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子,而Easy Math却没有。只要加一条特判,这道题就过了。

AC代码贴在下面。求莫比乌斯函数前缀和的那一部分是我当时在网上临时找的代码,向那位仁兄道谢。

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int Maxn = 1e7 * 2;
const int mod = 2333333;
int pcnt = 0, prime[1300000]; // 质数
short mu[Maxn]; // 莫比乌斯函数值
bool vis[Maxn];
void init() {
mu[1] = 1;
for (int i = 2; i < Maxn; i++) {
if (vis[i] == 0) {
mu[i] = -1;
prime[++pcnt] = i;
}
for (int j = 1; j <= pcnt && i * prime[j] < Maxn; j++) {
vis[i * prime[j]] = 1;
if (i % prime[j] != 0)
mu[i * prime[j]] = -mu[i];
else {
mu[i * prime[j]] = 0;
break;
}
}
}
for (int i = 2; i < Maxn; i++) mu[i] += mu[i - 1]; // 函数前缀和
}
struct Hash {
long long key;
int value, next;
} node[mod];
int cnt = 0, Head[mod] = {0};
void Insert(long long N, int v) { // 记忆
int ha = N % mod;
node[++cnt].key = N;
node[cnt].value = v;
node[cnt].next = Head[ha];
Head[ha] = cnt;
}
int M(long long N) {
if (N < Maxn) return mu[N];
int ha = N % mod;
for (int i = Head[ha]; i != 0; i = node[i].next) {
if (node[i].key == N) // 如果已经计算过
{return node[i].value;}
}
int ans = 0;
for (long long i = 2, j; i <= N; i = j + 1) {
j = N / (N / i); // 分块加速
ans += (j - i + 1) * M(N / i);
}
Insert(N, 1 - ans); // 做记忆
return 1 - ans;
} ll n,m;
long long fac[30];int cntfac;
bool init_fac(ll x)
{
cntfac=0;
for(int i=1;prime[i]<sqrt(x);++i)
if(x%prime[i]==0){fac[++cntfac]=prime[i];x/=prime[i];if(x%prime[i]==0)return false;}
if(x>1)fac[++cntfac]=x;
return true;
}
ll calc(ll n,ll m,int k)
{
//debug(n);
if(m==0)return 0;
if(n==1)
{
if(m==0)return 0;
else {return M(m);}
}
return -calc(n/fac[k],m,k-1)+calc(n,m/fac[k],k);
}
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("1.txt","w",stdout);
init();
while(~scanf("%lld%lld",&m,&n))
{
if(init_fac(n))printf("%lld\n",calc(n,m,cntfac));
else printf("0\n");
}
//freopen("CON","w",stdout);
//system("start Output.txt");
}

徐州赛区网络预赛 D Easy Math的更多相关文章

  1. [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]

    题目链接:Easy Math 题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum ...

  2. ACM-ICPC 2018 徐州赛区网络预赛(8/11)

    ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...

  3. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和

    链接 https://nanti.jisuanke.com/t/31456 参考题解  https://blog.csdn.net/ftx456789/article/details/82590044 ...

随机推荐

  1. Lisp-01: 相关开发环境配置部署

    Common Lisp 学习笔记系列01 要学一门编程语言,首先需要将语言的环境配置好.如果想要个直接上手的环境,感谢日本的大神 Shirakumo,打造了一个 Common Lisp 的 IDE - ...

  2. ThinkPHP6.0学习笔记-模型操作

    ThinkPHP模型 模型定义 在app目录下创建Model目录,即可创建模型文件 定义一个和数据库表相匹配的模型 use think\Model; class User extends Model ...

  3. 【php】日期时间

    一. 日期时间: a) 这是一块非常重要的内容,我们在windows当中,或者是将来要接触的定时器也好,都是需要使用到这一块内容的!二. PHP当中的日期时间: a) 时间戳:time()可以获取时间 ...

  4. .NET MVC中登录过滤器拦截的两种方法

    今天给大家介绍两种ASP中过滤器拦截的两种方法. 一种是EF 的HtppModule,另一种则是灵活很多针对MVC的特性类 Attribute 具体什么是特性类可以参考着篇文章:https://www ...

  5. javascript入门 之 用bootstrap-table写一个表格

    方法1(对普通的 table 设置 data-toggle="table" 即可): <!DOCTYPE html> <html> <head> ...

  6. 基础类封装-pymysql库操作mysql封装

    import pymysql from lib.logger import logger from warnings import filterwarnings filterwarnings(&quo ...

  7. WordPress文章阅读量统计和显示(非插件, 刷新页面不累加)

    本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. WordPress文章阅读 ...

  8. 22.4 Extends --super 和 this 的区别

    /* * this和super的区别 this:当前对象的引用 调用子类的成员变量 调用子类的成员方法 在子类的构造方法第一行调用子类其他构造方法 super:子类对象的父类引用 调用父类的成员变量 ...

  9. ASP.NET Core 3.1+MySQL 部署到docker上面使用docker-compose+DockerFile

    一.新建DockerFile文件 选择Linux版本 FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR ...

  10. 当Spring Cloud Alibaba Sentinel碰上Spring Cloud Sleuth会擦出怎样的火花

    前言 今年主要会做一个比较完整的微服务项目开源出来.目前已经开始了,刚兴趣的先Star一个吧. 项目:https://github.com/yinjihuan/kitty-cloud 基础框架:htt ...