2017-9-22 NOIP模拟赛[xxy][数论]
XXY 的 的 NOIP 模拟赛 4 4 —— 数学专场
A
Description
定义 f(x)表示 x 的约数和,例:f(12)=1+2+3+4+6+12=28
给出 x,y,求Σf(i),i∈[x,y]
Input
一行两个整数 x,y
Output
一行表示答案
Example
两组输入数据
2 4
123 321
对应输出
14
72543
Hint
对于 20%的数据,1<=x<=y<=1000
对于 40%的数据,1<=x<=y<=1e7
对于 100%的数据,1<=x<=y<=2e9
#include<iostream>
#include<cstdio>
using namespace std;
long long x,y;
long long count(int x){
long long res=;
long long l=,r;
while(){
r=x/(x/l);
long long a=x/l;
res+=((l+r)*(r-l+)/)*a;
l=r+;
if(x/l==)break;
}
return res;
}
int main(){
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
cin>>x>>y;
long long ansl=count(x-);
long long ansr=count(y);
cout<<ansr-ansl;
}
90分 出现整数被0除的错误
#include<iostream>
#include<cstdio>
using namespace std;
long long x,y;
long long count(int x){
long long res=;
long long l=,r;
while(){
if(x/l==)r=x;
else r=x/(x/l);
long long a=x/l;
res+=((l+r)*(r-l+)/)*a;
l=r+;
if(x/l==)break;
}
return res;
}
int main(){
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
cin>>x>>y;
long long ansl=count(x-);
long long ansr=count(y);
cout<<ansr-ansl;
}
100分
B
Description
求满足以下条件的 x 的个数
① x∈[1,n!]
② 设 pi 为质数且 pi|x,那么 pi>m,对于所有的 pi 均成立
答案对 100000007 取模
Input
一行两个整数 n,m
Output
一行表示答案
Example
3 组输入样例
100 10
100 20
10000 9000
Output
对应 3 组输出
43274465
70342844
39714141
Hint
对于 20%的数据,n,m<=8
对于 60%的数据,n<=100000,m<=8
对于 100%的数据,n<=10000000,保证 n-m<=100000,m<=n
学到的一点东西
1.x的所有素因子大于m,则x与m!互素
2.已知phi[(i-1)!],递推地求phi[i!]
如果i是素数,phi[i!]=phi[(i-1)!]*(i-1)
如果i不是素数,phi[i!]=phi[(i-1)!]*i
3.phi[n!]=phi[m!]*(n!/m!)
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int p[],n,m,w=,ans,cnt;
bool vis[],q[];
void dfs(int pos,long long sum){
if(sum>w)return;
if(!q[sum]&&sum!=)ans++,q[sum]=;
//cout<<sum<<' ';
for(int i=pos;i<=cnt;i++){
if(sum*p[i]>w)return;
dfs(i,sum*p[i]);
}
}
int main(){
//freopen("Cola.txt","r",stdin);
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)w*=i;
for(int i=;i<=w;i++){
if(!vis[i])p[++cnt]=i;
for(int j=;j<=cnt&&i*p[j]<=w;j++){
vis[i*p[j]]=;
if(i%p[j]==)break;
}
}
int pos=upper_bound(p+,p+cnt+,m)-p;
dfs(pos,);
for(int i=pos;i<=cnt;i++){
if(cnt>w)break;
if(!q[p[i]])ans++;
}
cout<<ans;
}
20分 暴力
#include<cstdio>
#define N 10000001
#define mod 100000007
using namespace std;
int cnt,p[],phi[N];
long long phifac[N];
bool v[N];
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
phi[]=;
for(int i=;i<N;i++)
{
if(!v[i])
{
p[++cnt]=i;
phi[i]=i-;
}
for(int j=;j<=cnt;j++)
{
if(i*p[j]>=N) break;
v[i*p[j]]=true;
if(i%p[j]) phi[i*p[j]]=phi[i]*(p[j]-);
else
{
phi[i*p[j]]=phi[i]*p[j];
break;
}
}
}
int n,m; long long ans;
scanf("%d%d",&n,&m);
ans=;
phifac[]=;
for(int i=;i<=m;i++)
if(!v[i]) phifac[i]=phifac[i-]*(i-)%mod;
else phifac[i]=phifac[i-]*i%mod;
ans=phifac[m];
for(int i=m+;i<=n;i++) ans=ans*i%mod;
printf("%I64d\n",ans-);
}
100分
C
Description
令 f(k)=n 表示 有 n 种方式,可以把正整数 k 表示成几个素数的乘积的形式。
例 10=2*5=5*2,所以 f(10)=2
给出 n,求最小的 k
Input
一行一个整数 n
Output
一行表示答案
Example
四组输入样例
1
2
3
105
对应输出:
2
6
12
720
Hint
20%的数据,k<=20
另外 20%的数据,n<=20
另外 20%的数据,k<=1e6
100%的数据,k,n<=2^60
#include<iostream>
#include<cstdio>
using namespace std;
long long a[];
int k,n,bin[],p[],cnt;
bool vis[];
bool check(int x){
int l=,pos=;
while(x!=){
while(x%p[pos]!=)pos++;
l=l+;
bin[l]=;
while(x%p[pos]==){
bin[l]++;
x=x/p[pos];
}
}
long long res=;
int sum=;
for(int i=;i<=l;i++)sum+=bin[i];
res=a[sum];
for(int i=;i<=l;i++)res/=a[bin[i]];
if(res==n)return ;
return ;
}
int main(){
//freopen("Cola.txt","r",stdin);
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
a[]=;
for(int i=;i<=;i++)a[i]=a[i-]*i;
scanf("%d",&n);
for(int i=;i<=;i++){
if(!vis[i])p[++cnt]=i;
for(int j=;j<=cnt&&i*p[j]<=;j++){
vis[i*p[j]]=;
if(i%p[j]==)break;
}
}
for(int i=;i<=;i++){//k的所有可能值
if(check(i)){
printf("%d",i);
return ;
}
}
}
30分 暴力枚举答案
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
int p[]={,,,,,,,,,,,,,,,,,,,,};
LL ans,n;
LL C[][];
void solve(int num,int lim,LL tot,LL now,int last)
{
if(now>ans) return;
if(tot==n) { ans=now; return ; }
if(tot>n || num>) return;
LL t=;
for(int i=;i<=lim;i++)
{
t*=p[num];
if(now>=ans/t) return;
solve(num+,i,tot*C[last+i][i],now*t,last+i);
}
}
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
C[][]=;
for(int i=;i<;i++)
{
C[i][]=;
for(int j=;j<=i;j++)
C[i][j]=C[i-][j-]+C[i-][j];
}
scanf("%I64d",&n);
if(n==)
{
printf("1 2\n");
return ;
}
ans=(LL)<<;
solve(,,,,);
printf("%I64d\n",ans);
}
100分 搜索+剪枝
2017-9-22 NOIP模拟赛[xxy][数论]的更多相关文章
- 2018.9.22 NOIP模拟赛
*注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A 妹子 Problem B 旅程 Problem C 老大 因为业务水平下滑太严重,去和高一考NOIP模拟,sad... P ...
- 2017.6.11 NOIP模拟赛
题目链接: http://files.cnblogs.com/files/TheRoadToTheGold/2017-6.11NOIP%E6%A8%A1%E6%8B%9F%E8%B5%9B.zip 期 ...
- 2017-9-13 NOIP模拟赛[xxy]
全排列 (permutation.cpp/c/pas)Description从 n 个不同元素中任取 m(m≤n)个元素,按照一定的顺序排列起来,叫做从 n个不同元素中取出 m 个元素的一个排列.当 ...
- 2017 10.25 NOIP模拟赛
期望得分:100+40+100=240 实际得分:50+40+20=110 T1 start取了min没有用,w(゚Д゚)w O(≧口≦)O T3 代码3个bug :数组开小了,一个细节没注意, ...
- 2017.5.27 NOIP模拟赛(hzwer2014-5-16 NOIP模拟赛)
期望得分:100+100+60+30=290 实际得分:100+20+60+0=180 当务之急:提高一次正确率 Problem 1 双色球(ball.cpp/c/pas) [题目描述] 机房来了新一 ...
- 18.9.22 noip模拟赛
此题为找规律.期望100 实际100 #include<cstdio> #include<cstring> #include<iostream> #include& ...
- 【2019.7.22 NOIP模拟赛 T1】麦克斯韦妖(demon)(质因数分解+DP)
暴力\(DP\) 先考虑暴力\(DP\)该怎么写. 因为每个序列之后是否能加上新的节点只与其结尾有关,因此我们设\(f_i\)为以\(i\)为结尾的最长序列长度. 每次枚举一个前置状态,判断是否合法之 ...
- 5.22 noip模拟赛
本来我是不想写的,无奈不会写.蒟蒻 考场就是想不出来 今天得到了100分额外水过了100分我是真的失败.还有一个根本不会check 感觉自己非常之菜. 这道题是这样的 还行吧比较有意思 首先确立一个真 ...
- 10.16 NOIP模拟赛
目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...
随机推荐
- Machine Learning No.10: Anomaly detection
1. Algorithm 2. evaluating an anomaly detection system 3. anomaly detection vs supervised learning 4 ...
- bind(),live(),delegate(),on()绑定事件方式
1.bind():向匹配元素添加一个或多个事件处理器. 适用所有版本,但是自从jquery1.7版本以后bind()函数推荐用on()来代替. $(selector).bind(event,data, ...
- 3D文字特效
在线演示 本地下载
- GDB调试core文件(2)
使用gdb和core dump迅速定位段错误 关键字:gdb.段错误.core dump 一.什么是core dump core:内存.核心的意思: dump:抛出,扔出: core dump:前提: ...
- SDUT OJ 2616 简单计算
简单计算 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 某天,XX 给YY 出了一道题,题目是: 给出n 个十进制的数,找出这n ...
- riverbed 流量分析——还是在基于流量做运维
from:https://www.riverbed.com/sg/digital-performance/index.htmlMaximise Your Digital PerformanceConn ...
- (转)epoll非阻塞读写规则
EPOLL技术 在linux的网络编程中,很长的时间都在使用select来做事件触发.在linux新的内核中,有了一种替换它的机制,就是epoll.相比于select,epoll最大的好处在于它不会随 ...
- leetcode 66. Plus One(高精度加法)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- 第十四章-MySQL
1 安装 MySQL常见的版本 GA: 广泛使用的版本 RC: 最接近正式版本 Alpha和Bean: 内测版本和公测版本 有两种安装方式: 安装包和压缩包 1) 安装msi文件 2) 解压zip文件 ...
- C++之MutexLock和MutexLockGuard封装
noncopyable.h #ifndef __WD_NONCOPYABLE_H__ #define __WD_NONCOPYABLE_H__ namespace wd { class Noncopy ...