結果

問題 No.434 占い
ユーザー miyo2580
提出日時 2024-02-08 23:25:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,559 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 208,968 KB
最終ジャッジ日時 2025-02-19 02:54:52
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 20 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
using Graph = vector<vector<ll>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1):n(n), f(n+1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
vector<pair<ll,int>> factor(ll x) {
vector<pair<ll,int>> res;
for (int p : primes) {
int y = 0;
while (x%p == 0) x /= p, ++y;
if (y != 0) res.emplace_back(p,y);
}
if (x != 1) res.emplace_back(x,1);
return res;
}
}sieve(350);
ll modpow(ll a, ll b, ll mod) {
ll res = 1;
while (b) {
if (b & 1)res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll T;cin>>T;
rep(ti,T){
string s;cin>>s;
bool flg=1;
ll n=s.size();
ll ans=s[0]-'0';
Graph g(n,vec(9));
repd(i,1,n){
vector<pair<ll,int>> v=sieve.factor(i);
for(auto[x,y]:v){
g[i][x%9]+=y;
}
}
rep(i,9){
rep(j,n-1)g[j+1][i]+=g[j][i];
}
repd(i,1,n){
if(s[i]!='0')flg=0;
ll now=1;
rep(j,9){
ll x=g[n-1][j]-g[n-1-i][j];
ll y=g[i][j];
x-=y;
x=modpow(j,x,9);
now*=x;
now%=9;
}
now*=s[i]-'0';
ans+=now;
}
ans%=9;
if(flg==0&&ans==0)ans=9;
cout<<ans<<'\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0