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^ ...
随机推荐
- jq_常用方法
//获取兄弟元素 $('.class').siblings() 当前元素所有的兄弟节点 $('.class').prev() 当前元素前一个兄弟节点 $('.class').prevaAll() 当前 ...
- textarea输入框实时统计输入字符数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- hdu 1253 胜利大逃亡(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题目大意:在所给的时间能顺利离开城堡. #include <iostream> #i ...
- python模块 zipfile
zipfile是python里用来做zip格式编码的压缩和解压缩的,由于是很常见的zip格式,所以这个模块使用频率也是比较高的zipfile里有两个非常重要的class, 分别是ZipFile和Zip ...
- redis cluster 实现
Redis cluster是一个redis官方提供的集群功能,集群节点最小3个节点,配置比较多,记录下来,以供下次使用.我在这使用的redis 4.0.6. 因为最新的ruby redis扩展需要ru ...
- 使用IDEA从github中下载fastdfs-client-java
由于在pom文件中加入依赖坐标无法将fastdfs-client-java下载下来,后来通过查资料,发现在中央仓库中没有定义该坐标.为此,使用idea从github下载fastdfs-client-j ...
- Unknown character set: 'utf8mb4'
出现Unknown character set: 'utf8mb4'该错误是因为你的mysql-connector-java版本太高了,现在的mysql编码方式utf8mb4 然而老版本的却是utf ...
- Network——物理层-练习题与解答
1. 无线电天线通常在其直径等于无线电波的波长的情况下工作效果最好.合理的天线直径的范围是从1厘米到5米.问所覆盖的频率范围是怎样的? 解答: λf = c , c=3x108 (m/s) 对于λ=1 ...
- C++ 输入ctrl+z 不能再使用cin的问题
问题介绍: 程序步骤是开始往容器里面写数据,以Ctrl+Z来终止输入流,然后需要输入一个数据,来判断容器中是否有这个数据. 源代码如下: #include<iostream> #inclu ...
- JS页面之间传值
父页面与子页面之间有多种传值的方式: 第一种,通过window.open的方法打开一个新的页面,在新的页面里面通过window.opener来获取对象,以下为实例 父页面: function open ...