BZOJ4454: C Language Practice
Description

Input
Output
Sample Input
3 2
5 9 6
3 4
2 2
8 9
0 6
1 1
9
6
Sample Output
22
3
然后整个算法分为两步:
1.预处理出1到N所有数的分解式与1到sqrt(N)内两两数的gcd。
int SIZE=(int)sqrt(N);
int ans=1,d;
for(int i=0;i<3;i++) {
if(x[i]<=SIZE) d=gcd[x[i]][y%x[i]];
else if(y%x[i]==0) d=x[i];
else d=1;
ans=ans*d;y=y/d;
}
正确性显然。
全代码:
#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=1000010;
int g[1010][1010],d[maxn],pri[maxn/10],cnt;
bool vis[maxn];
int A[maxn],B[maxn],C[maxn];
void init(int n) {
rep(i,0,1005) rep(j,0,i) {
if(!i||!j) g[i][j]=i+j;
else g[i][j]=g[j][i%j];
}
rep(i,0,1005) rep(j,i+1,1005) g[i][j]=g[j][i];
d[1]=1;
rep(i,2,n) {
if(!vis[i]) pri[++cnt]=i,d[i]=i;
rep(j,1,cnt) {
if(i*pri[j]>n) break;
vis[i*pri[j]]=1;
if(i%pri[j]==0) {d[i*pri[j]]=d[i];break;}
d[i*pri[j]]=pri[j];
}
}
A[1]=B[1]=C[1]=1;
rep(i,2,n) {
int j=i/d[i];A[i]=A[j];B[i]=B[j];C[i]=C[j];
if(A[i]*d[i]<=1000) A[i]*=d[i];
else if(B[i]*d[i]<=1000) B[i]*=d[i];
else C[i]*=d[i];
}
}
int X[3];
int gcd(int x,int y) {
if(!x||!y) return x+y;
if(x<=1000&&y<=1000) return g[x][y];
int c=0;
if(A[x]!=1) X[c++]=A[x];
if(B[x]!=1) X[c++]=B[x];
if(C[x]!=1) X[c++]=C[x];
int ans=1,d;
rep(i,0,c-1) {
if(X[i]<=1000) d=g[X[i]][y%X[i]];
else if(y%X[i]==0) d=X[i];
else d=1;
ans*=d;y/=d;
}
return ans;
}
int n,m,a[2010],b[2010];
int main() {
init(1000000);
dwn(T,read(),1) {
n=read();m=read();unsigned int ans=0;
rep(i,0,n-1) a[i]=read();
rep(i,0,m-1) b[i]=read();
rep(i,0,n-1) rep(j,0,m-1) ans+=gcd(a[i],b[j])^i^j;
printf("%u\n",ans);
}
return 0;
}
BZOJ4454: C Language Practice的更多相关文章
- BZOJ 4454: C Language Practice
4454: C Language Practice Time Limit: 20 Sec Memory Limit: 24 MBSubmit: 501 Solved: 112[Submit][St ...
- 英语口语考试资料Language learning
"Learning a language is easy. Even a child can do it!" Most adults who are learning a seco ...
- 100 天从 Python 新手到大师
Python应用领域和就业形势分析 简单的说,Python是一个“优雅”.“明确”.“简单”的编程语言. 学习曲线低,非专业人士也能上手 开源系统,拥有强大的生态圈 解释型语言,完美的平台可移植性 支 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Python - 100天从新手到大师
简单的说,Python是一个“优雅”.“明确”.“简单”的编程语言. 学习曲线低,非专业人士也能上手 开源系统,拥有强大的生态圈 解释型语言,完美的平台可移植性 支持面向对象和函数式编程 能够通过调用 ...
- 国内某Python大神自创完整版,系统性学习Python
很多小伙伴纠结于这个一百天的时间,我觉得完全没有必要,也违背了我最初放这个大纲上来的初衷,我是觉得这个学习大纲还不错,自学按照这个来也能相对系统的学习知识,而不是零散细碎的知识最后无法整合,每个人的基 ...
- 课程五(Sequence Models),第二 周(Natural Language Processing & Word Embeddings) —— 0.Practice questions:Natural Language Processing & Word Embeddings
[解释] The dimension of word vectors is usually smaller than the size of the vocabulary. Most common s ...
- The 11 advantages of Java -Why you choose this language
Java is never just a language.There are lots of programming languages out there, and few of them mak ...
- Microsoft source-code annotation language (SAL) 相关
More info see: https://msdn.microsoft.com/en-us/library/hh916383.aspx Simply stated, SAL is an inexp ...
随机推荐
- SQL索引及视图常用语法
ALTER TABLE department ADD INDEX dept_name_idx (name); SHOW INDEX FROM department \G ALTER TABLE dep ...
- poj 2524:Ubiquitous Religions(并查集,入门题)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23997 Accepted: ...
- angularJS 二
angularJS 2.1 ngForm <!DOCTYPE html> <html lang="zh-cn" ng-app> <head> ...
- 跟着鸟哥学Linux系列笔记3-第11章BASH学习
跟着鸟哥学Linux系列笔记0-扫盲之概念 跟着鸟哥学Linux系列笔记0-如何解决问题 跟着鸟哥学Linux系列笔记1 跟着鸟哥学Linux系列笔记2-第10章VIM学习 认识与学习bash 1. ...
- 第十一篇:SOUI系统资源管理
SOUI资源管理模块 从前篇已经讲到在SOUI中所有资源文件通过一个uires.idx文件进行索引. 这里将介绍在程序中如何引用这些资源文件. 在SOUI系统中,资源文件通过一个统一的接口对象读取: ...
- 直接拿来用!最火的Android开源项目(完结篇)(转)
摘要:截至目前,在GitHub“最受欢迎的开源项目”系列文章中我们已介绍了40个Android开源项目,对于如此众多的项目,你是Mark.和码友分享经验还是慨叹“活到老要学到老”?今天我们将继续介绍另 ...
- 在Salesforce中可以对某一个Object的Standard Button或Link进行重写
在Salesforce中可以对某一个Object的Standard Button或Link进行重写,来实现我们特定的逻辑过程,比如:在删除某个Object之前要判断该Object的某个Field的状态 ...
- ios调用系统导航
#import "ViewController.h" #import <MapKit/MapKit.h> @interface ViewController () @p ...
- 通过PID获取进程路径的几种方法
通过PID获取进程路径的几种方法 想获得进程可执行文件的路径最常用的方法是通过GetModuleFileNameEx函数获得可执行文件的模块路径这个函数从Windows NT 4.0开始到现在的Vis ...
- service里面弹出对话框
如何在service里面弹出对话框先给一个需求:需要在service里面监听短信的接收,如果接收到短信了,弹出一个dialog来提示用户打开. 看看效果图:(直接在主桌面上弹出) service中弹出 ...