B - Calculation 2
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.
Input
For each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.
Output
For each test case, you should print the sum module 1000000007 in a line.
Sample Input
3
4
0
Sample Output
0
2
用个互斥原理就可以了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
//#define cl clear()
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
vector< int >v;
const double pi=acos(-1.0);
ll cal(ll x,ll n)
{
if(x==n) return 0;
int a=(n-1)/x;
return (x*a+(x*a*(a-1))/2)%mod;
}
ll solve(ll n)
{
ll x=n;
for(int i=2;i*i<=x;i++)
{
// cout<<"1"<<endl;
if(x%i==0)
{
v.pb(i);
while(x%i==0)
{
x/=i;
}
}
}
if(x>1) v.pb(x);
ll sum=0;
for(int i=1;i<(1<<v.size()) ;i++)
{
ll bits=0,ans=1;
for(int j=0;j<v.size() ;j++)
{
if((1<<j)&i)
{
bits++;
ans*=v[j];
}
}
if(bits&1)
sum=(sum+cal(ans,n))%mod;
else
{
sum=(sum-cal(ans,n));
while(sum<0)
sum+=mod;
}
}
return sum;
}
int main()
{
// freopen("output1.txt", "r", stdin);
ll n;
while(1)
{
v.clear();
sf("%I64d",&n);
if(n==0) return 0;
pf("%I64d\n",solve(n));
}
}
B - Calculation 2的更多相关文章
- OpenCASCADE Curve Length Calculation
OpenCASCADE Curve Length Calculation eryar@163.com Abstract. The natural parametric equations of a c ...
- hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律
http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...
- inconsistent line count calculation in projection snapshot
1.现象 在vs2013中,按Ctrl + E + D格式化.cshtml代码,vs2013系统崩溃.报:inconsistent line count calculation in projecti ...
- 贪心 HDOJ 4726 Kia's Calculation
题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...
- Calculation
定义一个Strategy接口,其中定义一个方法,用于计算 using System; using System.Collections.Generic; using System.Linq; usin ...
- WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results
GLES2.0: Some device will give a warning on compling shaders(yet the compling will succeed), and the ...
- VKP5 Price Calculation – List Variant & KZPBL (Delete site level)
List Variant: Configuration in Logistic General –> Retail Pricing –> Sales Price Calculation – ...
- hdu 2837 Calculation 指数循环节套路题
Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 3501 Calculation 2(欧拉函数)
Calculation 2 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Calculation(dfs+状压dp)
Problem 1608 - Calculation Time Limit: 500MS Memory Limit: 65536KB Total Submit: 311 Accepted: ...
随机推荐
- [leetcode]Largest Rectangle in Histogram @ Python
原题地址:https://oj.leetcode.com/problems/largest-rectangle-in-histogram/ 题意: Given n non-negative integ ...
- js,html-点击直接跳转到页面底/顶部
案例一:js控制,无滑动效果 <html> <body> <a href="javascript:void(0);" onclick="ja ...
- bug Spring Mvc中Jsp页面获取不到Controller中的变量
今天遇到了一个奇怪的问题: jsp代码如下: <h1>数据对比${name}</h1> 在controller里面,有赋值: @RequestMapping(value = & ...
- 部分Linux时区改为东八区的方法
直接上命令 CentOS: timedatectl set-timezone Asia/Shanghai timedatectl status date Alphine: apk add tzdata ...
- mysql和redis的区别
一..redis和mysql的区别总结 (1)类型上 从类型上来说,mysql是关系型数据库,redis是缓存数据库 (2)作用上 mysql用于持久化的存储数据到硬盘, ...
- Junit学习笔记之五:MockMVC
原文:https://blog.csdn.net/xiao_xuwen/article/details/52890730 随着RESTful Web Service的流行,测试对外的Service是否 ...
- [Aaronyang紫色博客] 写给自己的WPF4.5-Blend5公开课系列 2-更进一步
我的文章一定要做到对读者负责,否则就是失败的文章 --------- www.ayjs.net aaronyang技术分享 欢迎大家支持我的力作<[Aaronyang] 写给自己的 ...
- Vue 温故而知新 props如何双向属性绑定
传送门:https://cn.vuejs.org/v2/guide/components-custom-events.html https://segmentfault.com/q/101000001 ...
- elast alert
参考文档:<elast alert> 假设报错的内容为: ceph-rest-api service down At least 1 events occurred between 201 ...
- 开始逐步补充下相关Web知识,很多年没搞了....
<script type="text/javascript"> $(function(){ ShowProduct(); $("#ShowUserInfo&q ...