light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum
第一题给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em,
则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2.
代码如下:
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <iostream>
- #define M 10000005
- #define mod 1000000007
- #define ll unsigned long long
- using namespace std;
- ll prime[M/],cnt;
- bool f[M];
- void init()
- {
- int i,j;
- cnt=;
- for(i=;i<M;i++){
- if(!f[i]) prime[cnt++]=i;
- for(j=;j<cnt&&i*prime[j]<M;j++){
- f[i*prime[j]]=;
- if(i%prime[j]==) break;
- }
- }
- }
- ll solve(ll n)
- {
- ll ans=;
- for(ll i=;i<cnt&&(ll)prime[i]*prime[i]<=n;i++){
- if(n%prime[i]==){
- ll t=;
- n/=prime[i];
- while(n%prime[i]==){
- t++;
- n/=prime[i];
- }
- ans*=(ll)(+t*);
- }
- }
- if(n>) ans=*ans;
- return (ans+)/;
- }
- int main()
- {
- int t,ca=;
- ll n;
- init();
- scanf("%d",&t);
- while(t--){
- scanf("%llu",&n);
- printf("Case %d: %llu\n",++ca,solve(n));
- }
- return ;
- }
第二题给定一个数N,其质因子pi及个数ei给定,
则结果为(1+p1+p1^2+……+p1^ei+ei*p1^ei)*……*(1+pm+pm^2+……+pm^em+em*pm^em)+N.
代码如下:
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- #include <iostream>
- #define mod 1000000007
- #define ll long long
- using namespace std;
- ll Pow(ll a,int b)
- {
- ll ans=;
- while(b){
- if(b&) ans=(ans*a)%mod;
- b>>=;
- a=(a*a)%mod;
- }
- return ans;
- }
- ll sum(ll a,int b)
- {
- if(b==) return ;
- if(b&) return (+Pow(a,(b+)/))*sum(a,b/)%mod;
- else return ((+Pow(a,b/+))*sum(a,b/-)%mod+Pow(a,b/))%mod;
- }
- int main()
- {
- int t,ca=,n,p,e;
- scanf("%d",&t);
- while(t--){
- scanf("%d",&n);
- ll ans=,xx,num=;
- for(int i=;i<n;i++){
- scanf("%d%d",&p,&e);
- xx=Pow(p,e);
- num=(num*xx)%mod;
- xx=(xx*e)%mod;
- xx=(xx+sum(p,e))%mod;
- ans=(ans*xx)%mod;
- }
- printf("Case %d: %lld\n",++ca,(ans+num)%mod);
- }
- return ;
- }
light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum的更多相关文章
- Light oj 1236 - Pairs Forming LCM (约数的状压思想)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS Memor ...
- 1236 - Pairs Forming LCM
1236 - Pairs Forming LCM Find the result of the following code: long long pairsFormLCM( int n ) { ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- LightOJ 1236 - Pairs Forming LCM(素因子分解)
B - Pairs Forming LCM Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)
链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...
- LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- 1236 - Pairs Forming LCM -- LightOj1236 (LCM)
http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...
- LightOJ 1236 Pairs Forming LCM 合数分解
题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...
随机推荐
- spring cloud config 详解
Spring Cloud 为开发人员提供了一系列的工具来快速构建分布式系统的通用模型 .例如:配置管理.服务发现.断路由.智能路由.微代理.控制总线.一次性Token.全局锁.决策竞选.分布式sess ...
- 【Python学习笔记】Coursera课程《Using Python to Access Web Data 》 密歇根大学 Charles Severance——Week2 Regular Expressions课堂笔记
Coursera课程<Using Python to Access Web Data > 密歇根大学 Charles Severance Week2 Regular Expressions ...
- 【UOJ#164】清华集训2015V
QwQzcysky真是菜死了,这是我刚上高一的时候坤爷在夏令营讲的,可是今天才切掉…… 想想也神奇,一个2016.11才学会线段树的菜鸡,夏令营的时候居然听过Segment-Tree-Beats? 所 ...
- 设计模式之笔记--单例模式(Singleton)
单例模式(Singleton) 定义 单例模式(Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点. 类图 描述 类Singleton的构造函数的修饰符为private,防止用 ...
- [How to] 使用Xib来创建view
1.简介 代码库 正如之前博客介绍的,xib可定义页面的某个部分,特别当此部分区域的view集中并且还有一些相互关联性(如隐藏等)是i特别适合使用xib来进行封装. 本文为[How to]使用自定义c ...
- kivy安装
>>> os.system('pip install kivy')Collecting kivy Downloading Kivy-1.9.1-cp27-none-win_amd64 ...
- [ Python ] 基本数据类型及属性(下篇)
1. 基本数据类型 (1) list 列表 (2) tuple 元组 (3) dict 字典 (4) set 集合 2. list 列表方法 Python 内置的一种数据类型, ...
- mysql 5.1.7.17 zip安装 和 隔段时间服务不见了处理
Mysql社区版下载地址:http://dev.mysql.com/downloads/mysql/ 因为我的系统版本是64,因此这里下载x64版本.下载完之后解压至D:\Dev\Mysql(即为my ...
- HDU-5351
MZL's Border Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 并发容器ConcurrentHashMap与synchronized联合使用达到线程安全
http://blog.csdn.net/yansong_8686/article/details/50664338 map.put(KEY, map.get(KEY) + 1); 实际上并不是原子操 ...