第一题给定一个大数,分解质因数,每个质因子的个数为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的更多相关文章

  1. Light oj 1236 - Pairs Forming LCM (约数的状压思想)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...

  2. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  3. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  4. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  5. LightOJ 1236 - Pairs Forming LCM(素因子分解)

    B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  6. LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)

    链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...

  7. LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, ...

  8. 1236 - Pairs Forming LCM -- LightOj1236 (LCM)

    http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...

  9. LightOJ 1236 Pairs Forming LCM 合数分解

    题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...

随机推荐

  1. 特征工程(Feature Engineering)

    一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...

  2. Python3 面向对象编程高级语法

    1.静态方法: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:CarsonLi class Dog(object): def __init ...

  3. Python3 面向对象编程

    小案例: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:Bert import sys class Role(object): n=&qu ...

  4. exit()与_exit()区别

    exit()与_exit()都是用来终止进程的函数,当程序执行到两者函数时,系统将会无条件停止剩下操作,清除进程结构体相应信息,并终止进程运行. 二者的主要区别在于:exit()函数在执行时,系统会检 ...

  5. [linux]通过ssh远程设定各服务器时间,从而实现集群时间同步

    #!/usr/bin/env bash #all hosts should to sync time, all hosts should no password login echo other sy ...

  6. 动态计算文本的CGSize

    // 计算文本的size -(CGSize)sizeWithText:(NSString *)text maxSize:(CGSize)maxSize fontSize:(CGFloat)fontSi ...

  7. nginx配置文件的详细讲解

    user nginx nginx; #定义Nginx运行的用户和用户组worker_processes 1; #nginx进程数,建议设置为等于CPU总核心数worker_rlimit_nofile ...

  8. awk常见操作整理(更新)

    awk的基本结构 awk 'BEGIN{} pattern {} END {}' #pattern {} 部分是针对每行进行循环处理的,有pattern表示对匹配到的行处理,没有pattern表示对所 ...

  9. Mysql 数据库学习笔记05 触发器

    一.触发器 * 是由时间来出发某个操作,这些事件可以包括 insert.update.delete.等语句.当执行这些操作时,就会触发对应的操作. * 创建一个执行语句的触发器: create tri ...

  10. inux权限管理(1)

    1.linux系统文件普通权限 2.文件所属主的设置,组的指定 3.特殊权限 4.acl权限 5.su命令及其注意事项和sudo权限 6.权限管理的注意点 0.首先,在linux下用户账户是分角色的, ...