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^ ...
随机推荐
- Java线程总结(二)
自定义线程的数据可以共享,也可以不共享,这要看具体的实现方式. 1.不共享数据多线程实现方式: public class MyThread extends Thread{ private int co ...
- 完全教程 Aircrack-ng破解WEP、WPA-PSK加密利器
其 实关于无线基础知识的内容还是挺多的,但是由于本书侧重于BT4自身工具使用的讲解,若是再仔细讲述这些外围的知识,这就好比讲述DNS工具时还要把 DNS服务器的类型.工作原理及配置讲述一遍一样,哈哈, ...
- mysql中的enum型
enum设置后 值只能是给出的值中的其中一个 mysql> create table enum(e enum('1','2','3','4','5','6','7','8','9','10')) ...
- 数据结构--Avl树的创建,插入的递归版本和非递归版本,删除等操作
AVL树本质上还是一棵二叉搜索树,它的特点是: 1.本身首先是一棵二叉搜索树. 2.带有平衡条件:每个结点的左右子树的高度之差的绝对值最多为1(空树的高度为-1). 也就是说,AVL树,本质上 ...
- monkey测试===monkeyrunner测试教程(1)
1.安装测试环境 jdk 安装与配置 android sdk安装与配置 Python编辑器安装与配置 以上安装请自行百度教程 Monkeyrunner使用方法 http://www.android-d ...
- Linux内核中链表的实现与应用【转】
转自:http://blog.chinaunix.net/uid-27037833-id-3237153.html 链表(循环双向链表)是Linux内核中最简单.最常用的一种数据结构. ...
- write-ups
https://github.com/MarioVilas/write-ups https://github.com/Deplorable-Mountaineer/Robot_Dynamite htt ...
- glob模块的使用
glob模块 功能描述:glob模块可以使用Unix shell风格的通配符匹配符合特定格式的文件和文件夹,跟windows的文件搜索功能差不多.glob模块并非调用一个子shell实现搜索功能,而是 ...
- 学习1:python输入输出
1. 输出 >>> print "hello world" hello world >>> print 'hello world' hello ...
- 算法入门系列1:k-means
k-means是一种无监督学习算法,用于聚类. 下图(来自http://www.cnblogs.com/jerrylead/archive/2011/04/06/2006910.html)展示了k-m ...