Generate view queries using a loop
If I understand you correctly below anonymous block should do it.
DO $$
declare 

tabs cursor for
SELECT table_name
FROM information_schema.tables
WHERE table_name LIKE '%^prefix%'
  AND table_name NOT LIKE '%suffix$'
  AND table_schema not in ('information_schema', 'pg_catalog')
  AND table_type = 'BASE TABLE'
ORDER BY table_name;
rec record;

query_statement text;
BEGIN

open tabs;
loop
fetch tabs into rec;

exit when not found;

    FOR i IN 0..20 LOOP
         
    query_statement:= 'CREATE MATERIALIZED VIEW IF NOT EXISTS &quot;'||rec.table_name||'_factor'||i||'&quot; AS SELECT id, POWER(2,'||i||') AS factor FROM &quot;'||rec.table_name||'&quot; WHERE factor IS NOT NULL;';
    RAISE NOTICE '%' , query_statement;
    RAISE NOTICE 'factor number is: %', i;
    END LOOP;
end loop;
END; $$