K Simple question (第十届山东理工大学ACM网络编程擂台赛 正式赛)
2024-08-27 06:34:37
题解:素数筛+唯一分解定理
可以把素数筛那部分放到while之外,减小时间复杂度。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
const int maxn = 110000005;
const int mod = 100000007;
const int N = 60000008;
int prime[N];
bool vis[maxn];
int main()
{
int n;
while(~scanf("%d",&n)){
assert(1 <= n && n <= 100000000);
long long ans = 1;
int cnt=0;
memset(vis,false, sizeof(vis));
for (int i = 2; i <= n; i++)
{
if (!vis[i])
{
prime[cnt++] = i;
for (long long j = i; j <= n; j *= i)
{
ans = ans * i % mod;
}
}
for (int j = 0; j < cnt; j++)
{
long long x = i * prime[j];
if (x > n)break;
vis[x] = true;
if (i%prime[j] == 0)break;
}
}
printf("%lld\n",ans);
}
return 0;
}
最新文章
- OC-《购票系统》
- 在windows上搭建react-native的android环境
- web api 开发记录
- json_encode中文unicode的问题
- 也不知怎么了LVS.SH找不到,网上搜了一篇环境搭配CENTOS下面的高可用 参考
- FreeSWITCH一些需求应对
- 2659: [Beijing wc2012]算不出的算式 - BZOJ
- NSString+URLEncoding.h --使用Obj-C对数据等进行URLEncoding编码
- Oracle 监听器无法启动(TNS-12555,TNS-12560,TNS-00525)
- duilib之源码分析
- Windows 驱动发展基金会(九)内核函数
- 克隆虚拟机win8系统后注意修改安全标识(SID)
- 【iOS】swift 74个Swift标准库函数
- IrisSkin 单独控件样式设置 不使用皮肤样式
- Delphi 2010 新增功能之: IOUtils 单元(6): TPath(结构体) 的方法与属性
- 在vue2.0中引用element-ui组件库
- poj1664放苹果(递归)
- 5月16 JSON的一些知识点及AJAX的应用
- inception+archery SQL审核平台
- 使用express框架和mongoose在MongoDB删除数据
热门文章
- 【转载】网站配置Https证书系列(二):IIS服务器给网站配置Https证书
- 微信开发者工具 关于no such file or directory
- ios9 字符串与UTF-8 互相转换
- Redis系列之-—内存淘汰策略(笔记)
- CentOS7安装CDH 第八章:CDH中对服务和机器的添加与删除操作
- layui 添加
- Django中使用JWT
- Linux的desktop文件正常编写赋权,仍无法打开解决办法
- {RuntimeError} An attempt has been made to start a new process before the current process has finished its bootstrapping phase.This probably means that you are not using fork to start your child...
- MySQL面试问题