結果
問題 | No.886 Direct |
ユーザー |
![]() |
提出日時 | 2019-09-13 22:09:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,300 ms / 4,000 ms |
コード長 | 1,328 bytes |
コンパイル時間 | 1,447 ms |
コンパイル使用メモリ | 170,420 KB |
実行使用メモリ | 194,864 KB |
最終ジャッジ日時 | 2024-07-04 09:49:31 |
合計ジャッジ時間 | 67,219 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#undef _P#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))//-------------------------------------------------------ll mo=1000000007;ll H,W;ll A[3030303];vector<int> P[3030303];void solve() {int i,j,k,l,r,x,y; string s;cin>>H>>W;ll ret=0;// 横と縦ret=((W-1)*H+(H-1)*W)%mo;for(y=1;y<=H-1;y++) A[y]=H-y;for(y=1;y<=3000000;y++) {for(i=y*2;i<=3000000;i+=y) A[y]+=A[i];A[y]%=mo;}for(y=2;y<=3010101;y++) if(P[y].empty()) {for(i=y;i<=3010101;i+=y) P[i].push_back(y);}ll v=0;for(x=1;x<=W-1;x++) {int mask;FOR(mask,1<<P[x].size()) {ll v=1;FOR(i,P[x].size()) if(mask&(1<<i)) v*=P[x][i];if(__builtin_popcount(mask)%2==0) ret+=(W-x)*2*A[v]%mo;else ret-=(W-x)*2*A[v]%mo;}}cout<<(ret%mo+mo)%mo<<endl;}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);cout.tie(0); solve(); return 0;}