luogu P2257 YY的GCD

嘟嘟嘟

感覺這幾道數論題都差不多,但這到明顯是前幾道的升級版。
推了一大頓只能得60分,不得不看題解。
各位看這老哥的題解吧
我就是推到他用\(T\)換掉\(kd\)之前,然后枚舉\(T\)的。這個轉換確實想不出來啊。
還有最后一句,最終的式子
\[\sum_{T = 1} ^ {n} \lfloor \frac{n}{T} \rfloor \lfloor \frac{m}{T} \rfloor * \sum_{k | T} \mu(\frac{T}{k}) (k \in prime)\]
他把后面的那個sum預處理了。令\(f(T) = \sum_{k | T} \mu(\frac{T}{k}) (k \in prime)\),由此可見,這個函數的自變量是\(T\),而預處理的時候是枚舉\(T\)的質因數累加得到\(f(T)\),跟埃氏篩法很像。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("") 
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e7 + 5;
inline ll read()
{ll ans = 0;char ch = getchar(), last = ' ';while(!isdigit(ch)) last = ch, ch = getchar();while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();if(last == '-') ans = -ans;return ans;
}
inline void write(ll x)
{if(x < 0) x = -x, putchar('-');if(x >= 10) write(x / 10);putchar(x % 10 + '0');
}int v[maxn], prm[maxn], mu[maxn];
ll f[maxn], sum[maxn];
void init()
{mu[1] = 1;for(int i = 2; i < maxn; ++i){if(!v[i]) v[i] = i, prm[++prm[0]] = i, mu[i] = -1;for(int j = 1; j <= prm[0] && i * prm[j] < maxn; ++j){v[i * prm[j]] = prm[j];if(i % prm[j] == 0) {mu[i * prm[j]] = 0; break;}else mu[i * prm[j]] = -mu[i];}}for(int i = 1; i <= prm[0]; ++i)for(int j = 1; prm[i] * j < maxn; ++j)f[prm[i] * j] += mu[j];for(int i = 1; i < maxn; ++i) sum[i] = sum[i - 1] + f[i];
}ll solve(int n, int m)
{int Min = min(n, m);ll ret = 0;for(int l = 1, r; l <= Min; l = r + 1){r = min(n / (n / l), m / (m / l));ret += (sum[r] - sum[l - 1]) * (n / l) * (m / l);}return ret;
}int main()
{init();int T = read();while(T--){ll n = read(), m = read();write(solve(n, m)), enter;}return 0;
}

轉載于:https://www.cnblogs.com/mrclr/p/10112023.html

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

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

相關文章

20.4. myisamchk — MyISAM Table-Maintenance Utility

先停止mysqld&#xff0c;在--datadir目錄運行 myisamchk */*.MYI >/dev/null &#xff03;檢查哪些表需要修復修復用以下命令一個個修復&#xff1a; myisamchk -r table.MYI更省事的做法&#xff1a; myisamchk -r /var/lib/mysql/*.MYImyisamchk可用crontab定時最佳化tab…

火狐ok谷歌適配_“ OK Google”在鎖定手機上的安全性越來越高

火狐ok谷歌適配If you use “OK Google” to invoke the Assistant on your phone, things are about to change. Google is removing the “Unlock with Voice Match” feature, so the Assistant is going to get a lot more secure. 如果您使用“確定Google”在手機上調用助…

angular ng-zorro 用組件自身方的法來重置表單校驗

官網文檔的API并沒有提供對應的重置表單校驗函數の說明&#xff0c;在控制臺打印this.validateForm&#xff08;校驗表單對象&#xff09; 往往我們只關注亮色函數、屬性&#xff0c;而這次重置函數藏在__prop__中&#xff01; 激動萬分的使用 this.validateForm.reset()&…

Django用戶注冊、登錄、注銷(一)

使用Django自帶的用戶認證系統編寫認證、登錄、注銷基本功能 功能&#xff1a; 使用Django默認的User表 1&#xff09;注冊 判斷是否已存在此用戶&#xff0c;存在的話提示報錯“用戶已存在”&#xff1b; 判斷兩次輸入的密碼是否一致&#xff0c;不一致的話提示報錯“密碼不一…

1月3日學習內容整理:modelform

1、modelform本質上還是form組件 2、引入 from django.forms import ModelForm 3、創建 class Form(ModelForm): class Meta: modelBook Book就是models.py中定義的類&#xff0c;也就是表 firelds"_ _all_ _" 代表繼承Book表中的所有字…

如何在PowerPoint中自動調整圖片大小

PowerPoint can automatically resize an image to fit a shape. You can also resize multiple images already in your presentation to all be the same size. Here’s how it works. PowerPoint可以自動調整圖像大小以適合形狀。 您還可以將演示文稿中已有的多個圖像調整為…

vue目錄結構

vue目錄結構參考一參考二參考三參考一 目錄一級二級bulid項目構建的一些 js 文件config配置文件項&#xff0c;index.js 比較重要&#xff0c;打包上線需要修改配置dist項目打包后的文件node_modulesnpm安裝包位置src項目的開發目錄-assets圖片、字體等資源-components公共組件…

js獲取當前日期

var myDate new Date(); myDate.getYear(); //獲取當前年份(2位) myDate.getFullYear(); //獲取完整的年份(4位,1970-????) myDate.getMonth(); //獲取當前月份(0-11,0代表1月) myDate.getDate(); //獲取當前日(1-31) myDate.getDay(); //獲取當前星期X(0-6,0代表星期天) …

如何在不支付Adobe Photoshop費用的情況下處理Camera Raw

You might think that you need expensive software to take advantage of Camera RAW—something like Photoshop or the more modestly priced Lightroom. Fortunately there is freeware that can help you achieve professional results without professional costs. 您可能…

eclipse 代碼提示后面的百分比是什么意思?

簡而言之&#xff0c;就是提示你其他人&#xff08;開發人員&#xff09;在此情形下使用該方法百分比&#xff0c;最常用方法百分比 見http://www.eclipse.org/recommenders/manual/#d0e32 Call Completion The Call Completion engine, for example, provides you with recomm…

python實現關聯規則

代碼中Ci表示候選頻繁i項集&#xff0c;Li表示符合條件的頻繁i項集    # codingutf-8    def createC1(dataSet): # 構建所有1項候選項集的集合    C1 []    for transaction in dataSet:    for item in transaction:    if [item] not in C1:   …

Progressive Web App(PWA)

Progressive Web App一、 PWA 宣傳 &#xff1a; Reliable &#xff08; 可靠的 &#xff09;、Fast&#xff08; 快速的 &#xff09;、Engaging&#xff08; 可參與的 &#xff09;二、什么是Progressive三、為什么我們需要Progressive Web App一、 PWA 宣傳 &#xff1a; Re…

travis-cli 使用

1. 添加項目登錄 travis 選擇對應項目即可 2. 添加持續集成文件.travis.ymllanguage: node_js node_js:- "node" before_install: - npm install -g jspm - jspm install script: - jspm bundle lib/main --inject備注&#xff1a;這是一個jspm 項目 3. 構建travis 是…

在Windows Media Center中收聽超過100,000個廣播電臺

A cool feature in Windows 7 Media Center is the ability to listen to local FM radio. But what if you don’t have a tuner card that supports a connected radio antenna? The RadioTime plugin solves the problem by allowing access to thousands of online radio …

vue項目中按需引入viewUI

viewUI一、按需引入二、忽略eslint編譯器檢測和編譯檢測1.忽略編譯器檢測2.編譯器中忽略一、按需引入 npm install babel-plugin-import --save-dev // .babelrc1 { “plugins”: [[“import”, { “libraryName”: “view-design”, “libraryDirectory”: “src/components”…

IntelliJ IDEA——數據庫集成工具(Database)的使用

idea集成了一個數據庫管理工具&#xff0c;可以可視化管理很多種類的數據庫&#xff0c;意外的十分方便又好用。這里以oracle為例配置。 1、配置 在窗口的右邊有個Database按鈕&#xff0c;點擊。 如果沒有&#xff0c;請點擊上方的View(視圖)-Tool Windows(工具窗口)-Database…

為什么VC經常輸出燙燙燙燙燙燙燙燙

在Debug 模式下&#xff0c; VC 會把未初始化的棧內存全部填成0xcc&#xff0c;當字符串看就是 燙燙燙燙……會把未初始化的堆內存全部填成0xcd&#xff0c;當字符串看就是 屯屯屯屯……可以讓我們方便地看出那些內存沒初始化但是Release 模式下不會有這種附加動作&#xff0c;…

代碼評審會議_如何將電話會議(和訪問代碼)另存為聯系人

代碼評審會議Dialing a conference call doesn’t have to be a tedious process. Your iPhone or Android phone can automatically dial into the call and enter a confirmation code for you. You just have to create a special type of contact. 撥打電話會議不一定是一個…

Vuex使用總結

Vuex綜合使用一、倉庫1.主倉庫2.子倉庫二、使用1.全局&#xff08;index.js和未開啟命名空間的子倉庫&#xff09;2.子倉庫&#xff08;子倉庫定義了namespaced: true&#xff09;&#xff0c;倉庫名&#xff1a;home3.使用strict嚴格模式&#xff08;建議&#xff09;三、批量…

好未來提前批

好未來提前批(注&#xff1a;轉載于牛客網) 一面&#xff08;25minutes&#xff09; 1.創建對象的幾種方式2.Jsp九大隱式對象3.自己封裝的持久層框架用過么4.Spring ioc讓你實現怎么實現呢&#xff08;工廠反射&#xff0c;我半年前寫過&#xff0c;忘記了&#xff09;5.Aop的實…