BZOJ 2818 Gcd

傳送門

題解:設p為素數 ,則gcd(x/p,y/p)=1也就是說求 x/p以及 y/p的歐拉函數。歐拉篩+前綴和就可以解決

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
#include <iomanip>
#include <set>
#include<ctime>
//#include<unordered_map>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define fio ios::sync_with_stdio(false);cin.tie(0)
const int N=1e7+10;
const ull base=163;
const int INF=0x3f3f3f3f;
using namespace std;
bool ispri[N];
ll pri[N],phi[N];
int tot=0;
void getphi(int x)
{memset(ispri,1,sizeof(ispri));ispri[1]=false;phi[1]=1;for(int i=2;i<=x;i++){if(ispri[i]){pri[++tot]=i;phi[i]=i-1;}for(int j=1;j<=tot&&i*pri[j]<=x;j++){ispri[i*pri[j]]=false;if(i%pri[j]==0){phi[i*pri[j]]=phi[i]*pri[j];break;}phi[i*pri[j]]=phi[i]*(pri[j]-1);}}
}
ll sum[N];
int main(){int n;cin>>n;getphi(n);ll ans=0;for(int i=1;i<=n;i++)sum[i]=phi[i]+sum[i-1];for(int i=1;i<=tot;++i){ans+=sum[n/pri[i]]*2-1;}cout<<ans<<endl;return 0;
}

?

轉載于:https://www.cnblogs.com/Mrleon/p/9097806.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389551.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389551.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389551.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

LeetCode387-字符串中的第一個唯一字符(查找,自定義數據結構)

一開始想用HashMap&#xff0c;把每個字符放進去&#xff0c;然后統計出現的次數。 使用LinkedHashMap的話&#xff0c;鍵值對的順序都是不會變的。 LinkedHashMap<Character,Integer> map new LinkedHashMap<>();map.put(i,1111);map.put(j,2222);map.put(k,3333…

r psm傾向性匹配_南瓜香料指標psm如何規劃季節性廣告

r psm傾向性匹配Retail managers have been facing an extraordinary time with the COVID-19 pandemic. But the typical plans to prepare for seasonal sales will be a new challenge. More seasonal products have been introduced over the years, making August the bes…

主成分分析:PCA的思想及鳶尾花實例實現

主成份分析算法PCA 非監督學習算法 PCA的實現&#xff1a; 簡單來說&#xff0c;就是將數據從原始的空間中轉換到新的特征空間中&#xff0c;例如原始的空間是三維的(x,y,z)&#xff0c;x、y、z分別是原始空間的三個基&#xff0c;我們可以通過某種方法&#xff0c;用新的坐…

兩家大型網貸平臺竟在借款人審核問題上“偷懶”?

python信用評分卡&#xff08;附代碼&#xff0c;博主錄制&#xff09; https://study.163.com/course/introduction.htm?courseId1005214003&utm_campaigncommission&utm_sourcecp-400000000398149&utm_mediumshare 放貸流量增加&#xff0c;逾期率也會隨之增加&…

解決 Alfred 每次開機都提示請求通訊錄權限的問題

安裝完 Alfred 以后&#xff0c;每次開機都會提示請求通訊錄權限&#xff0c;把設置里的通訊錄關掉也沒用&#xff0c;每次都提示又非常煩人&#xff0c;這里把解決方法記錄一下。 依次打開 應用程序 - Alfred 3.app - 右鍵顯示包內容 - Contents - Frameworks - Alfred Framew…

【轉】DCOM遠程調用權限設置

原文&#xff1a;https://blog.csdn.net/ervinsas/article/details/36424127 最近幾天被搞得焦頭爛額&#xff0c;由于DCOM客戶端程序是在32位系統下開發的&#xff0c;調試時DCOM服務端也是安裝在同一臺機器上&#xff0c;所有過程一直還算順利。可這次項目實施的時候&#xf…

opencv:邊緣檢測之Laplacian算子思想及實現

Laplacian算子邊緣檢測的來源 在邊緣部分求取一階導數&#xff0c;你會看到極值的出現&#xff1a; 如果在邊緣部分求二階導數會出現什么情況? 從上例中我們可以推論檢測邊緣可以通過定位梯度值大于鄰域的相素的方法找到(或者推廣到大 于一個閥值). 從以上分析中&#xff0c…

使用機器學習預測天氣_如何使用機器學習預測著陸

使用機器學習預測天氣Based on every NFL play from 2009–2017根據2009-2017年每場NFL比賽 Ah, yes. The times, they are changin’. The leaves are beginning to fall, the weather is slowly starting to cool down (unless you’re where I’m at in LA, where it’s on…

laravel 導出插件

轉發&#xff1a;https://blog.csdn.net/gu_wen_jie/article/details/79296470 版本&#xff1a;laravel5 php 5.6 安裝步驟&#xff1a; 一、安裝插件 ①、首先在Laravel項目根目錄下使用Composer安裝依賴&#xff1a; composer require "maatwebsite/excel:~2.1.0"…

國外 廣告牌_廣告牌下一首流行歌曲的分析和預測,第1部分

國外 廣告牌Using Spotify and Billboard’s data to understand what makes a song a hit.使用Spotify和Billboard的數據來了解歌曲的流行。 Thousands of songs are released every year around the world. Some are very successful in the music industry; others less so…

Jmeter測試普通java類說明

概述 Apache JMeter是Apache組織開發的基于Java的壓力測試工具。本文檔主要描述用Jmeter工具對基于Dubbo、Zookeeper框架的Cassandra接口、區塊鏈接口進行壓力測試的一些說明&#xff0c;為以后類似接口的測試提供參考。 環境部署 1、 下載Jmeter工具apache-jmeter-3.3.zip&am…

opencv:Canny邊緣檢測算法思想及實現

Canny邊緣檢測算法背景 求邊緣幅度的算法&#xff1a; 一階導數&#xff1a;sobel、Roberts、prewitt等算子 二階導數&#xff1a;Laplacian、Canny算子 Canny算子效果比其他的都要好&#xff0c;但是實現起來有點麻煩 Canny邊緣檢測算法的優勢&#xff1a; Canny是目前最優…

關于outlook簽名圖片大小的說明

96 dpiwidth576 height114轉載于:https://blog.51cto.com/lch54734/2298115

opencv:畸變矯正:透視變換算法的思想與實現

畸變矯正 注意&#xff1a;雖然能夠成功矯正但是也會損失了部分圖像&#xff01; 透視變換(Perspective Transformation) 概念&#xff1a; 透視變換是將圖片投影到一個新的視平面(Viewing Plane)&#xff0c;也稱作投影映射(Projective Mapping)。 我們常說的仿射變換是透視…

數據多重共線性_多重共線性對您的數據科學項目的影響比您所知道的要多

數據多重共線性Multicollinearity is likely far down on a mental list of things to check for, if it is on a list at all. This does, however, appear almost always in real-life datasets, and it’s important to be aware of how to address it.多重共線性可能根本不…

PHP工廠模式計算面積與周長

<?phpinterface InterfaceShape{ function getArea(); function getCircumference();}/** * 矩形 */class Rectangle implements InterfaceShape{ private $width; private $height; public function __construct($width,$height){ $this->width$…

K-Means聚類算法思想及實現

K-Means聚類概念&#xff1a; K-Means聚類是最常用的聚類算法&#xff0c;最初起源于信號處理&#xff0c;其目標是將數據點劃分為K個類簇&#xff0c; 找到每個簇的中心并使其度量最小化。 該算法的最大優點是簡單、便于理解&#xff0c;運算速度較快&#xff0c;缺點是只能應…

(2.1)DDL增強功能-數據類型、同義詞、分區表

1.數據類型 &#xff08;1&#xff09;常用數據類型  1.整數類型 int 存儲范圍是-2,147,483,648到2,147,483,647之間的整數&#xff0c;主鍵列常設置此類型。 &#xff08;每個數值占用 4字節&#xff09; smallint 存儲范圍是-32,768 到 32,767 之間的整數&#xff0c;用…

充分利用昂貴的分析

By Noor Malik努爾馬利克(Noor Malik) Let’s say you write a query in Deephaven which performs a lengthy and expensive analysis, resulting in a live table. For example, in a previous project, I wrote a query which pulled data from an RSS feed to create a li…

【java并發編程藝術學習】(一)初衷、感想與筆記目錄

不忘初心&#xff0c;方得始終。 學習java編程這么長時間&#xff0c;自認為在項目功能需求開發中沒啥問題&#xff0c;但是之前的幾次面試和跟一些勤奮的或者小牛、大牛級別的人的接觸中&#xff0c;才發現自己的無知與淺薄。 學習總得有個方向吧&#xff0c;現階段就想把并發…